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

   - [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
   - [ ] Read the [ASF Generative Tooling 
Guidance](https://www.apache.org/legal/generative-tooling.html) if you use 
Artificial Intelligence (AI).
   - [ ] 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?
   - [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`: `FastDateFormat.getInstance("YYYY").format(cal)` where `cal` is 15 
July 42 BC, that is a `GregorianCalendar` with `ERA` set to 
`GregorianCalendar.BC`.
   `Expected`: `-0041`, what `SimpleDateFormat` prints for the same date and 
pattern.
   `Actual`: `000` followed by `U+0007`. `YY` gives `,/` against 
`SimpleDateFormat`'s `-41`.
   
   1. `GregorianCalendar.getWeekYear()` is proleptic, so a BC date gives a 
negative week year (`-41` here) and `WeekYear` hands it to the wrapped 
`NumberRule` unchanged.
   2. The digit rules build each character arithmetically (`(char) (value + 
'0')`, `value / 10 + '0'`), so a negative value walks below `'0'` and lands on 
control characters or unrelated code points rather than digits.
   
   `Fix`: emit the sign in `WeekYear` and pass the magnitude down, the same 
handling `TimeZoneNumberRule` and `Iso8601_Rule` already apply to negative UTC 
offsets. Every other rule takes its value from `Calendar.get`, which never 
returns a negative, so `getWeekYear` is the only source of one; `YYY` and `Y` 
keep the four-digit padding the class Javadoc describes.
   
   Checked `YYYY` against `SimpleDateFormat` over 46,667 dates spanning 249 BC 
to 4188 AD: 2,611 mismatches before this change, 337 of them carrying a control 
character, and 0 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]

Reply via email to