-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix timezone parsing regression in FastDateParser #1543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @ujwal2203
Thank you for your PR.
-1 as the PR stands: Your PR is missing a unit test to show your change to main actually fixes something. The new test should fail if the change to the main side of the tree is not applied.
Gary
|
Ping @ujwal2203 Your PR is missing a unit test to show your change to main actually fixes something. See my previous comment #1543 (review) |
Changed the expression "(Z|(?:[+-]\\d{2}(?::?)\\d{2}))" to "(Z|(?:[+-]\\d{2}(?::)\\d{2}))"
Added a JUnit test method in FastDateParserTest to improve coverage for ISO-8601 timezone parsing behavior. The test verifies that FastDateParser correctly supports the existing ISO-8601 timezone formats, including: - Z (UTC) - ±HH - ±HHMM - ±HH:MM This aligns the test suite with the current implementation and ensures backward compatibility for accepted timezone variants.
|
Summary Adjusted ISO-8601 timezone parsing to preserve backward-compatible behavior while clarifying supported formats. The change ensures that both colon-separated and non-colon timezone offsets continue to be accepted, consistent with historical behavior in Commons Lang. Testing Added a JUnit test method in FastDateParserTest to explicitly cover supported ISO-8601 timezone formats:
Compatibility
Checklist
|
ujwal2203
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did changes in test method
|
Hello @ujwal2203 Thank you for your update. Please rebase this PR on git master. |
|
Hello @ujwal2203 There are no regressions based on the current state of this PR, which no longer matches its title. I added Thank you. |
|
Yeah it was a new experience and its my first time thanks for you kindness and patience @garydgregory closing the PR |
Summary
Fixes timezone parsing regression in FastDateParser that broke backward compatibility in commons-lang 3.5+.
Problem
DateUtils.parseDate with pattern "yyyy-MM-dd'T'HH:mm:ss.SSSZZ" fails to parse timezone offsets without colon (e.g., -0500) in versions 3.5+. This worked in version 3.4.
Example failing code:
// This throws ParseException in 3.5+ but worked in 3.4
DateUtils.parseDate("2019-06-11T15:06:11.716-0500", "yyyy-MM-dd'T'HH:mm:ss.SSSZZ");
Root Cause
The regex pattern for ISO_8601_3_STRATEGY in FastDateParser.java requires a colon between hours and minutes: (?::).
The current regex at line 923:
private static final Strategy ISO_8601_3_STRATEGY = new ISO8601TimeZoneStrategy("(Z|(?:[+-]\d{2}(?::)\d{2}))");
Solution
Changed the regex to make colon optional: (?::?). This allows both formats:
Updated regex:
private static final Strategy ISO_8601_3_STRATEGY = new ISO8601TimeZoneStrategy("(Z|(?:[+-]\d{2}(?::?)\d{2}))");
Changes Made
Testing Considerations
References
Checklist
Fixes: LANG-1805