-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[LANG-1637] Fix 2 digit week year formatting #688
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -432,4 +432,19 @@ public void testDayNumberOfWeek() { | |
| calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); | ||
| assertEquals("7", printer.format(calendar.getTime())); | ||
| } | ||
|
|
||
| @DefaultLocale(language = "en", country = "US") | ||
| @DefaultTimeZone("America/New_York") | ||
| @Test | ||
| public void testWeekYear() { | ||
| final GregorianCalendar cal = new GregorianCalendar(2020, 12, 31, 0, 0, 0); | ||
| final DatePrinter printer4Digits = getInstance("YYYY"); | ||
| final DatePrinter printer4DigitsFallback = getInstance("YYY"); | ||
| final DatePrinter printer2Digits = getInstance("YY"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi,
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add code in your new test for Y and YYY.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added, thanks |
||
| final DatePrinter printer4DigitAnotherFallback = getInstance("Y"); | ||
| assertEquals("2021", printer4Digits.format(cal)); | ||
| assertEquals("2021", printer4DigitsFallback.format(cal)); | ||
| assertEquals("2021", printer4DigitAnotherFallback.format(cal)); | ||
| assertEquals("21", printer2Digits.format(cal)); | ||
| } | ||
| } | ||
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.
I am not convinced by this because it patches the wrong spot.
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.
the name TwoDigitYearField implies this class encapsulates formatting of year field to a 2 digit string. as such, it seems reasonable for it to have the logic to take any year integer and map it to a decade followed by a year digits.
you can also see that the other method in this class
void appendTo(Appendable buf, Calendar calendar) throws IOExceptionimplementing the Rule interface, does the same
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.
@garydgregory WDYT?
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.
Hi @michael-o
Earlier you said "I am not convinced by this because it patches the wrong spot." implying there was a "right" spot, but where would that be?
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.
I think here: https://issues.apache.org/jira/browse/LANG-1637?focusedCommentId=17257625&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17257625 and this method must throw IAE
if (value >= 100).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.
Well... which way is this one going to go? @ugonen Are you going to update your PR or @michael-o do you want to provide a different PR?
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.
I think for the ease of use we have to use this one because my solution leaks abstraction. It makes too many assumptions about in the delegated
NumberRule