Skip to content

Commit

Permalink
Rewrite the testParsingDatesFormattedWithSystemLocale(), Fix google…
Browse files Browse the repository at this point in the history
…#2199 (google#2287)

* Rewrite the `testParsingDatesFormattedWithSystemLocale()`, Fix google#2199

* Format the test

* Format the code following Google Java Style Guide

* Revert "Format the code following Google Java Style Guide"

This reverts commit f5e2e16.

(cherry picked from commit 6c12ded)
  • Loading branch information
MaicolAntali authored and tibor-universe committed Jan 18, 2023
1 parent f861617 commit b97092d
Showing 1 changed file with 20 additions and 17 deletions.
Expand Up @@ -77,32 +77,35 @@ private void assertFormattingAlwaysEmitsUsLocale(Locale locale) {
}

public void testParsingDatesFormattedWithSystemLocale() throws Exception {
// TODO(eamonnmcmanus): fix this test, which fails on JDK 8 and 17
if (JavaVersion.getMajorJavaVersion() != 11) {
return;
}
TimeZone defaultTimeZone = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
Locale defaultLocale = Locale.getDefault();
Locale.setDefault(Locale.FRANCE);
try {
String afterYearSep1 = JavaVersion.isJava9OrLater() ? JavaVersion.getMajorJavaVersion() < 16 ? " à " : ", " : " ";
String afterYearSep2 = JavaVersion.isJava9OrLater() ? " à " : " ";
assertParsed(String.format("1 janv. 1970%s00:00:00", afterYearSep1),
Date date = new Date(0);
assertParsed(
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(date),
DateType.DATE.createDefaultsAdapterFactory());
assertParsed("01/01/70", DateType.DATE.createAdapterFactory(DateFormat.SHORT));
assertParsed("1 janv. 1970", DateType.DATE.createAdapterFactory(DateFormat.MEDIUM));
assertParsed("1 janvier 1970", DateType.DATE.createAdapterFactory(DateFormat.LONG));
assertParsed("01/01/70 00:00",
assertParsed(
DateFormat.getDateInstance(DateFormat.SHORT).format(date),
DateType.DATE.createAdapterFactory(DateFormat.SHORT));
assertParsed(
DateFormat.getDateInstance(DateFormat.MEDIUM).format(date),
DateType.DATE.createAdapterFactory(DateFormat.MEDIUM));
assertParsed(
DateFormat.getDateInstance(DateFormat.LONG).format(date),
DateType.DATE.createAdapterFactory(DateFormat.LONG));
assertParsed(
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(date),
DateType.DATE.createAdapterFactory(DateFormat.SHORT, DateFormat.SHORT));
assertParsed(String.format("1 janv. 1970%s00:00:00", afterYearSep1),
assertParsed(
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(date),
DateType.DATE.createAdapterFactory(DateFormat.MEDIUM, DateFormat.MEDIUM));
assertParsed(String.format("1 janvier 1970%s00:00:00 UTC", afterYearSep2),
assertParsed(
DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(date),
DateType.DATE.createAdapterFactory(DateFormat.LONG, DateFormat.LONG));
assertParsed(JavaVersion.isJava9OrLater() ? (JavaVersion.getMajorJavaVersion() < 11 ?
"jeudi 1 janvier 1970 à 00:00:00 Coordinated Universal Time" :
"jeudi 1 janvier 1970 à 00:00:00 Temps universel coordonné") :
"jeudi 1 janvier 1970 00 h 00 UTC",
assertParsed(
DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(date),
DateType.DATE.createAdapterFactory(DateFormat.FULL, DateFormat.FULL));
} finally {
TimeZone.setDefault(defaultTimeZone);
Expand Down

0 comments on commit b97092d

Please sign in to comment.