[LANG-1637] Fix 2 digit week year formatting (#688)

* LANG-1637: fix 2 digit week year formatting

* LANG-1637: added test cases for Y & YYY patterns

* LANG-1637: added test cases for Y & YYY patterns

* LANG-1637: added test cases for Y & YYY patterns
This commit is contained in:
Uri Gonen 2021-01-06 22:51:14 +02:00 committed by GitHub
parent 2a8356cd43
commit 63f644daa8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -1118,7 +1118,7 @@ public class FastDatePrinter implements DatePrinter, Serializable {
*/
@Override
public final void appendTo(final Appendable buffer, final int value) throws IOException {
appendDigits(buffer, value);
appendDigits(buffer, value % 100);
}
}

View File

@ -432,4 +432,19 @@ public class FastDatePrinterTest {
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");
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));
}
}