Skip to content

Commit

Permalink
Merge pull request #1224 from HubSpot/allow-jdk21-build
Browse files Browse the repository at this point in the history
Change tests to accept jdk21 locales for date/time formatting
  • Loading branch information
jasmith-hs authored Dec 6, 2024
2 parents 131dbb1 + 2b18dc7 commit ce3106c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public void itInterpretsFormattedDates() {
)
);

assertThat(result).isEqualTo("Oct 20, 2022, 5:09:43 PM");
assertThat(result).isIn("Oct 20, 2022, 5:09:43 PM", "Oct 20, 2022, 5:09:43 PM");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ public void itConvertsToLocaleSpecificDateTimeFormat() {
"en-US"
)
)
.isEqualTo("10/11/18 1:09:45 PM - Oct 11, 2018, 1:09:45 PM");
.isIn(
"10/11/18 1:09:45 PM - Oct 11, 2018, 1:09:45 PM",
"10/11/18 1:09:45 PM - Oct 11, 2018, 1:09:45 PM"
);
assertThat(
filter.filter(
1539277785000L,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void itFormatsNumbers() {
assertThat(
jinjava.render("{{ d | format_datetime }}", ImmutableMap.of("d", 1668120547000L))
)
.isEqualTo("Nov 10, 2022, 10:49:07 PM");
.isIn("Nov 10, 2022, 10:49:07 PM", "Nov 10, 2022, 10:49:07 PM");
}

@Test
Expand All @@ -47,15 +47,15 @@ public void itFormatsPyishDates() {
assertThat(
jinjava.render("{{ d | format_datetime }}", ImmutableMap.of("d", pyishDate))
)
.isEqualTo("Nov 10, 2022, 10:49:07 PM");
.isIn("Nov 10, 2022, 10:49:07 PM", "Nov 10, 2022, 10:49:07 PM");
}

@Test
public void itFormatsZonedDateTime() {
assertThat(
jinjava.render("{{ d | format_datetime }}", ImmutableMap.of("d", DATE_TIME))
)
.isEqualTo("Nov 10, 2022, 10:49:07 PM");
.isIn("Nov 10, 2022, 10:49:07 PM", "Nov 10, 2022, 10:49:07 PM");
}

@Test
Expand All @@ -78,7 +78,7 @@ public void itUsesShortFormat() {
ImmutableMap.of("d", DATE_TIME)
)
)
.isEqualTo("11/10/22, 10:49 PM");
.isIn("11/10/22, 10:49 PM", "11/10/22, 10:49 PM");
}

@Test
Expand All @@ -89,23 +89,26 @@ public void itUsesMediumFormat() {
ImmutableMap.of("d", DATE_TIME)
)
)
.isEqualTo("Nov 10, 2022, 10:49:07 PM");
.isIn("Nov 10, 2022, 10:49:07 PM", "Nov 10, 2022, 10:49:07 PM");
}

@Test
public void itUsesLongFormat() {
assertThat(
jinjava.render("{{ d | format_datetime('long') }}", ImmutableMap.of("d", DATE_TIME))
)
.isEqualTo("November 10, 2022 at 10:49:07 PM Z");
.isIn("November 10, 2022 at 10:49:07 PM Z", "November 10, 2022, 10:49:07 PM Z");
}

@Test
public void itUsesFullFormat() {
assertThat(
jinjava.render("{{ d | format_datetime('full') }}", ImmutableMap.of("d", DATE_TIME))
)
.isEqualTo("Thursday, November 10, 2022 at 10:49:07 PM Z");
.isIn(
"Thursday, November 10, 2022 at 10:49:07 PM Z",
"Thursday, November 10, 2022, 10:49:07 PM Z"
);
}

@Test
Expand Down Expand Up @@ -140,7 +143,7 @@ public void itUsesGivenTimeZone() {
ImmutableMap.of("d", DATE_TIME)
)
)
.isEqualTo("November 10, 2022 at 5:49:07 PM EST");
.isIn("November 10, 2022 at 5:49:07 PM EST", "November 10, 2022, 5:49:07 PM EST");
}

@Test
Expand Down Expand Up @@ -230,6 +233,6 @@ public void itUsesJinjavaConfigIfNullLocalePassed() {
ImmutableMap.of("d", DATE_TIME)
)
)
.isEqualTo("11/10/22, 5:49 PM");
.isIn("11/10/22, 5:49 PM", "11/10/22, 5:49 PM");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ public void itFormatsNumbers() {
assertThat(
jinjava.render("{{ d | format_time }}", ImmutableMap.of("d", 1668120547000L))
)
.isEqualTo("10:49:07 PM");
.isIn("10:49:07 PM", "10:49:07 PM");
}

@Test
public void itFormatsPyishDates() {
PyishDate pyishDate = new PyishDate(1668120547000L);

assertThat(jinjava.render("{{ d | format_time }}", ImmutableMap.of("d", pyishDate)))
.isEqualTo("10:49:07 PM");
.isIn("10:49:07 PM", "10:49:07 PM");
}

@Test
public void itFormatsZonedDateTime() {
assertThat(jinjava.render("{{ d | format_time }}", ImmutableMap.of("d", DATE_TIME)))
.isEqualTo("10:49:07 PM");
.isIn("10:49:07 PM", "10:49:07 PM");
}

@Test
Expand All @@ -71,31 +71,31 @@ public void itUsesShortFormat() {
assertThat(
jinjava.render("{{ d | format_time('short') }}", ImmutableMap.of("d", DATE_TIME))
)
.isEqualTo("10:49 PM");
.isIn("10:49 PM", "10:49 PM");
}

@Test
public void itUsesMediumFormat() {
assertThat(
jinjava.render("{{ d | format_time('medium') }}", ImmutableMap.of("d", DATE_TIME))
)
.isEqualTo("10:49:07 PM");
.isIn("10:49:07 PM", "10:49:07 PM");
}

@Test
public void itUsesLongFormat() {
assertThat(
jinjava.render("{{ d | format_time('long') }}", ImmutableMap.of("d", DATE_TIME))
)
.isEqualTo("10:49:07 PM Z");
.isIn("10:49:07 PM Z", "10:49:07 PM Z");
}

@Test
public void itUsesFullFormat() {
assertThat(
jinjava.render("{{ d | format_time('full') }}", ImmutableMap.of("d", DATE_TIME))
)
.isEqualTo("10:49:07 PM Z");
.isIn("10:49:07 PM Z", "10:49:07 PM Z");
}

@Test
Expand Down Expand Up @@ -127,7 +127,7 @@ public void itUsesGivenTimeZone() {
ImmutableMap.of("d", DATE_TIME)
)
)
.isEqualTo("5:49:07 PM EST");
.isIn("5:49:07 PM EST", "5:49:07 PM EST");
}

@Test
Expand Down Expand Up @@ -195,7 +195,7 @@ public void itUsesMediumIfNullFormatPassed() {
ImmutableMap.of("d", DATE_TIME)
)
)
.isEqualTo("17:49:07");
.isIn("17:49:07", "5:49 PM");
}

@Test
Expand All @@ -217,6 +217,6 @@ public void itUsesJinjavaConfigIfNullLocalePassed() {
ImmutableMap.of("d", DATE_TIME)
)
)
.isEqualTo("5:49 PM");
.isIn("5:49 PM", "5:49 PM");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void itFormatsTimes() {
ImmutableMap.of("d", ZonedDateTime.of(2022, 11, 28, 16, 30, 4, 0, ZoneOffset.UTC))
)
)
.isEqualTo("4:30:04 PM");
.isIn("4:30:04 PM", "4:30:04 PM");
}

@Test
Expand All @@ -48,6 +48,6 @@ public void itFormatsDateTimes() {
ImmutableMap.of("d", ZonedDateTime.of(2022, 11, 28, 16, 30, 4, 0, ZoneOffset.UTC))
)
)
.isEqualTo("Nov 28, 2022, 4:30:04 PM");
.isIn("Nov 28, 2022, 4:30:04 PM", "Nov 28, 2022, 4:30:04 PM");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public void testWithNoPcts() {

@Test
public void testDateTime() {
assertThat(StrftimeFormatter.format(d, "%c")).isEqualTo("Nov 6, 2013, 2:22:00 PM");
assertThat(StrftimeFormatter.format(d, "%c"))
.isIn("Nov 6, 2013, 2:22:00 PM", "Nov 6, 2013, 2:22:00 PM");
}

@Test
Expand All @@ -73,12 +74,13 @@ public void testDayOfWeekNumber() {

@Test
public void testTime() {
assertThat(StrftimeFormatter.format(d, "%X")).isEqualTo("2:22:00 PM");
assertThat(StrftimeFormatter.format(d, "%X")).isIn("2:22:00 PM", "2:22:00 PM");
}

@Test
public void testMicrosecs() {
assertThat(StrftimeFormatter.format(d, "%X %f")).isEqualTo("2:22:00 PM 123000");
assertThat(StrftimeFormatter.format(d, "%X %f"))
.isIn("2:22:00 PM 123000", "2:22:00 PM 123000");
}

@Test
Expand All @@ -98,7 +100,7 @@ public void testPaddedMinFmt() {
@Test
public void testFinnishMonths() {
assertThat(StrftimeFormatter.format(d, "long", Locale.forLanguageTag("fi")))
.startsWith("6. marraskuuta 2013 klo 14.22.00");
.isIn("6. marraskuuta 2013 klo 14.22.00 UTC", "6. marraskuuta 2013 14.22.00 UTC");
}

@Test
Expand Down

0 comments on commit ce3106c

Please sign in to comment.