alhudz opened a new pull request, #1842: URL: https://github.com/apache/commons-lang/pull/1842
Thanks for your contribution to [Apache Commons](https://commons.apache.org/)! Your help is appreciated! Before you push a pull request, review this list: - [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project. - [x] Read the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) if you use Artificial Intelligence (AI). - [x] I used AI to create any part of, or all of, this pull request. Which AI tool was used to create this pull request, and to what extent did it contribute? Claude Code (Anthropic) found the bug and drafted the patch, the test and this description; I reviewed and verified them before submitting. - [x] Run a successful build using the default [Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command line by itself. - [x] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice. - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. - [x] Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process. Repro: with the default zone `Europe/London`, call `DateUtils.ceiling(date, Calendar.MINUTE)` for `date` = 2024-10-27T01:08:58.245+01:00, the first (BST) pass of the repeated 01:00-02:00 hour. Expected: 01:09:00 BST, two seconds later. Actual: 01:09:00 GMT, an hour and two seconds later. `round` to `MINUTE` returns the same instant, `ceiling` to `HOUR_OF_DAY` returns 02:00 GMT instead of 02:00 BST, and `round` of 01:38 BST to `HOUR_OF_DAY` returns 02:00 GMT. Any zone with a fall-back overlap is affected (New York, Berlin, Auckland, Sao Paulo in the differential run below). Cause: `modify()` subtracts milliseconds, seconds and minutes from the epoch time (the LANG-59 block) only when they round down; a value at or above the halfway point is cleared in the field loop with `Calendar.set()`, which recomputes the instant from the wall clock, and `GregorianCalendar` resolves an ambiguous wall time to standard time. `truncate` is unaffected because its arithmetic path always runs, which is why `testTruncateLang59` (truncate and round down only) did not catch it. Fix: remove `MILLISECOND`, `SECOND` and `MINUTE` arithmetically in the loop too, so the instant keeps its offset. `DATE` and larger fields still use `Calendar.set()` for wall-clock semantics. A differential run against `java.time` over 400,000 instants in eight zones (1920 to 2030) goes from 17 `ceiling` and 17 `round` mismatches to 0; the one remaining case is a Lord Howe 30-minute DST gap that `truncate` shares. `testCeilingAndRoundDstOverlap` fails before the change and passes after. -- 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]
