Alwaysgaurav1 commented on PR #1780:
URL: https://github.com/apache/commons-lang/pull/1780#issuecomment-5512201131

   @garydgregory Rebased on `master` and updated the fix to unify the token 
cascading hierarchy.
   
   ### Root Cause of the Test Failure
   In the previous commit, `start.add(Calendar.YEAR, 1)` clamped `2020-02-29` 
to `2021-02-28`. Because initial `days` subtracted `29` (`1 - 29 = -28`), 
adding the 28 days of February 2021 resulted in `-28 + 28 = 0` days instead of 
`1` day.
   
   ### Solution
   We keep the exact same normalization behavior by unifying how omitted tokens 
are cascaded (`y -> M -> d -> H -> m -> s -> S`):
   1. Apply standard hierarchical borrowing for `days` and `months` first (same 
as when `M` is present).
   2. If `y` is omitted, roll `years` into `months` (`months += 12 * years; 
years = 0;`).
   3. If `M` is omitted, roll remaining `months` into `days`:
      ```java
      if (!Token.containsTokenWithValue(tokens, M)) {
          while (months > 0) {
              days += start.getActualMaximum(Calendar.DAY_OF_MONTH);
              months -= 1;
              start.add(Calendar.MONTH, 1);
          }
      }


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to