Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ public void appendTo(final Appendable buffer, final Calendar calendar) throws IO
*/
@Override
public final void appendTo(final Appendable buffer, final int value) throws IOException {
appendDigits(buffer, value);
appendDigits(buffer, value % 100);
Copy link
Member

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.

Copy link
Contributor Author

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 IOException
implementing the Rule interface, does the same

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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?

Copy link
Member

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

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Copy link
Member

@garydgregory garydgregory Dec 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
Thank you for your PR.
What about "YYY"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add code in your new test for Y and YYY.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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));
}
}