Alwaysgaurav1 opened a new pull request, #1801:
URL: https://github.com/apache/commons-lang/pull/1801

   ## Summary
   Fixes [LANG-796](https://issues.apache.org/jira/browse/LANG-796).
   
   In `DateUtils`, the `addXXX(Date, int)` methods (e.g., `addDays`, 
`addHours`) internally delegate to `Calendar.getInstance()` using the host 
machine's default time zone and locale. When performing arithmetic across 
Daylight Saving Time (DST) transitions (such as Europe/Brussels on March 25, 
2012):
   - Wall-clock calendar addition preserves the hour/minute (e.g., `00:00`), 
but elapsed time is 23 or 25 hours rather than 24 hours.
   - Results vary depending on the host machine's default time zone (e.g., UTC 
cloud servers vs. developer workstations in Europe/US).
   
   Changing existing 2-argument methods would break backward compatibility for 
applications relying on calendar wall-clock arithmetic. This PR addresses the 
issue by adding overloaded `add` and `addXXX` methods that accept an explicit 
`TimeZone` parameter.
   
   ## Changes
   - Added `public static Date add(Date date, int calendarField, int amount, 
TimeZone timeZone)`
   - Added `TimeZone` overloads for:
     - `addDays(Date, int, TimeZone)`
     - `addHours(Date, int, TimeZone)`
     - `addMilliseconds(Date, int, TimeZone)`
     - `addMinutes(Date, int, TimeZone)`
     - `addMonths(Date, int, TimeZone)`
     - `addSeconds(Date, int, TimeZone)`
     - `addWeeks(Date, int, TimeZone)`
     - `addYears(Date, int, TimeZone)`
   - Passing `TimeZones.GMT` allows callers to perform deterministic physical 
time arithmetic (exactly 24h per day) immune to DST changes.
   - Passing a specific `TimeZone` ensures deterministic calendar arithmetic 
independent of `TimeZone.getDefault()`.
   - Existing 2-argument methods preserve 100% backward compatibility by 
falling back to `TimeZones.toTimeZone(null)`.
   - Updated Javadoc with `@since 3.21.0` and logged in 
`src/changes/changes.xml`.
   - Added unit tests for each new method and a regression test verifying the 
Europe/Brussels spring (23h) and autumn (25h) DST transitions alongside GMT 
(24h).
   
   ## Verification
   - `mvn test -Dtest="org.apache.commons.lang3.time.*Test"`: 58,152 tests 
passed (0 failures, 0 errors)
   - `mvn checkstyle:check`: 0 violations
   - `mvn apache-rat:check`: Passed


-- 
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