BAEL-6985: Patterns With Locales (#14808)

This commit is contained in:
Eugene Kovko 2023-09-24 04:22:37 +02:00 committed by GitHub
parent 1a9337f238
commit 8171a4604f
1 changed files with 44 additions and 9 deletions

View File

@ -96,7 +96,8 @@ public class DateTimeFormatterUnitTest {
String newYorkDateTimePattern = "dd.MM.yyyy HH:mm z";
DateTimeFormatter newYorkDateFormatter = DateTimeFormatter.ofPattern(newYorkDateTimePattern);
LocalDateTime summerDay = LocalDateTime.of(2016, 7, 31, 14, 15);
Assert.assertEquals("31.07.2016 14:15 EDT", newYorkDateFormatter.format(ZonedDateTime.of(summerDay, ZoneId.of("America/New_York"))));
Assert.assertEquals("31.07.2016 14:15 EDT",
newYorkDateFormatter.format(ZonedDateTime.of(summerDay, ZoneId.of("America/New_York"))));
}
@Test
@ -121,8 +122,10 @@ public class DateTimeFormatterUnitTest {
@Test
public void shouldPrintFormattedDateTimeWithPredefined() {
Assert.assertEquals("2018-03-09", DateTimeFormatter.ISO_LOCAL_DATE.format(LocalDate.of(2018, 3, 9)));
Assert.assertEquals("2018-03-09-03:00", DateTimeFormatter.ISO_OFFSET_DATE.format(LocalDate.of(2018, 3, 9).atStartOfDay(ZoneId.of("UTC-3"))));
Assert.assertEquals("Fri, 9 Mar 2018 00:00:00 -0300", DateTimeFormatter.RFC_1123_DATE_TIME.format(LocalDate.of(2018, 3, 9).atStartOfDay(ZoneId.of("UTC-3"))));
Assert.assertEquals("2018-03-09-03:00",
DateTimeFormatter.ISO_OFFSET_DATE.format(LocalDate.of(2018, 3, 9).atStartOfDay(ZoneId.of("UTC-3"))));
Assert.assertEquals("Fri, 9 Mar 2018 00:00:00 -0300",
DateTimeFormatter.RFC_1123_DATE_TIME.format(LocalDate.of(2018, 3, 9).atStartOfDay(ZoneId.of("UTC-3"))));
}
@Test
@ -191,4 +194,36 @@ public class DateTimeFormatterUnitTest {
public void shouldExpectAnExceptionIfSecondIsMissing() {
ZonedDateTime zonedDateTime = ZonedDateTime.parse("2021-12-02T08:06Z", DateTimeFormatter.ISO_INSTANT);
}
@Test
public void testUSShortFormatting() {
LocalDate date = LocalDate.of(2023, 9, 18);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd, yy: EEE").withLocale(Locale.US);
String formattedDate = date.format(formatter);
Assert.assertEquals("Sep 18, 23: Mon", formattedDate);
}
@Test
public void testUSFullFormatting() {
LocalDate date = LocalDate.of(2023, 9, 18);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM dd, yyyy: EEEE").withLocale(Locale.US);
String formattedDate = date.format(formatter);
Assert.assertEquals("September 18, 2023: Monday", formattedDate);
}
@Test
public void testKoreanShortFormatting() {
LocalDate date = LocalDate.of(2023, 9, 18);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd, yy: EEE").withLocale(Locale.KOREA);
String formattedDate = date.format(formatter);
Assert.assertEquals("9월 18, 23: 월", formattedDate);
}
@Test
public void testKoreanFullFormatting() {
LocalDate date = LocalDate.of(2023, 9, 18);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM dd, yyyy: EEEE").withLocale(Locale.KOREA);
String formattedDate = date.format(formatter);
Assert.assertEquals("9월 18, 2023: 월요일", formattedDate);
}
}