Skip to content

Commit 887d5c3

Browse files
authored
Merge pull request #60 from salesforce/revert-ICU-21301-fix
Revert #56 - ICU-21301 fix
2 parents 5be5092 + 8544d1c commit 887d5c3

File tree

2 files changed

+7
-67
lines changed

2 files changed

+7
-67
lines changed

src/main/java/com/force/i18n/BaseLocalizer.java

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public enum LocalOrGmt {
5252
private static Function<Locale, FormatFixer> LocaleFixerFunction;
5353

5454
// controlls leniency of parsing date. using non-lenient mode for not allowing ambiguous date such as "2/30"
55+
// set true to avoid ICU-21301 that fails to parse the transition date for time zones with daylight saving time
5556
private static final boolean USE_LENIENT_MODE = false;
5657

5758
static {
@@ -822,22 +823,6 @@ public DateFormat getInputLongDateFormat() {
822823
return this.inputLocalLongDateFormat;
823824
}
824825

825-
826-
/**
827-
* Copy over the settings from ICU {@code SimpleDateFormat}.
828-
* <p>
829-
* ICU-21301 fails to parse the transition date for time zones with daylight saving time.
830-
831-
* see: https://unicode-org.atlassian.net/browse/ICU-21301
832-
*/
833-
private static DateFormat setJdkDateFormatFromIcu(SimpleDateFormat fmtJdk, SimpleDateFormatICU fmtIcu) {
834-
fmtJdk.applyPattern(fmtIcu.toPattern());
835-
fmtJdk.setNumberFormat(fmtIcu.getNumberFormat());
836-
fmtJdk.setDateFormatSymbols(fmtIcu.getDateFormatSymbols());
837-
fmtJdk.set2DigitYearStart(fmtIcu.get2DigitYearStart());
838-
return fmtJdk;
839-
}
840-
841826
/**
842827
* Static method to get date-only DateFormat for input. This is based on a 2 digit year
843828
* input mask, which also handles 4-digit year, but caller must use doParseDate() to
@@ -850,13 +835,6 @@ private static DateFormat setJdkDateFormatFromIcu(SimpleDateFormat fmtJdk, Simpl
850835
*/
851836
public static DateFormat getLocaleInputDateFormat(Locale locale, TimeZone tz) {
852837
DateFormat df = getFormatProvider(locale).getDateInstance(DateFormat.SHORT, locale);
853-
// ICU-21301 hack: Apply only with an ICU object and when timezone has DST
854-
if (!USE_LENIENT_MODE && df instanceof SimpleDateFormatICU && tz.useDaylightTime()) {
855-
// (re-)construct JDK's DateFormat object and copy formatting information from ICU
856-
DateFormat dfJdk = getJDKFormatFixer().getDateInstance(DateFormat.SHORT, locale);
857-
df = setJdkDateFormatFromIcu((SimpleDateFormat)dfJdk, (SimpleDateFormatICU)df);
858-
}
859-
860838
df.setLenient(USE_LENIENT_MODE);
861839
df.setTimeZone(tz);
862840
set2DigitYearStart(df, tz);
@@ -885,13 +863,6 @@ public static DateFormat getLocaleInputDateFormat(Locale locale, int style, Time
885863
dateStyle = DateFormat.SHORT;
886864
}
887865
DateFormat df = getFormatProvider(locale).getDateInstance(dateStyle, locale);
888-
// ICU-21301 hack: Apply only with an ICU object and when timezone has DST
889-
if (!USE_LENIENT_MODE && df instanceof SimpleDateFormatICU && tz.useDaylightTime()) {
890-
// (re-)construct JDK's DateFormat object and copy formatting information from ICU
891-
DateFormat dfJdk = getJDKFormatFixer().getDateInstance(dateStyle, locale);
892-
df = setJdkDateFormatFromIcu((SimpleDateFormat)dfJdk, (SimpleDateFormatICU)df);
893-
}
894-
895866
df.setLenient(USE_LENIENT_MODE);
896867
df.setTimeZone(tz);
897868
set2DigitYearStart(df, tz);
@@ -986,13 +957,6 @@ public DateFormat getInputLongDateTimeFormat() {
986957
*/
987958
public static DateFormat getLocaleInputDateTimeFormat(Locale locale, TimeZone tz) {
988959
DateFormat df = getFormatProvider(locale).getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale);
989-
// ICU-21301 hack: Apply only with an ICU object and when timezone has DST
990-
if (!USE_LENIENT_MODE && df instanceof SimpleDateFormatICU && tz.useDaylightTime()) {
991-
// (re-)construct JDK's DateFormat object and copy formatting information from ICU
992-
DateFormat dfJdk = getJDKFormatFixer().getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale);
993-
df = setJdkDateFormatFromIcu((SimpleDateFormat)dfJdk, (SimpleDateFormatICU)df);
994-
}
995-
996960
df.setLenient(USE_LENIENT_MODE);
997961
df.setTimeZone(tz);
998962
set2DigitYearStart(df, tz);
@@ -1027,12 +991,6 @@ public static DateFormat getLocaleInputDateTimeFormat(Locale locale, int style,
1027991
dateStyle = timeStyle = DateFormat.SHORT;
1028992
}
1029993
DateFormat df = getFormatProvider(locale).getDateTimeInstance(dateStyle, timeStyle, locale);
1030-
// ICU-21301 hack: Apply only with an ICU object and when timezone has DST
1031-
if (!USE_LENIENT_MODE && df instanceof SimpleDateFormatICU && tz.useDaylightTime()) {
1032-
// (re-)construct JDK's DateFormat object and copy formatting information from ICU
1033-
DateFormat dfJdk = getJDKFormatFixer().getDateTimeInstance(dateStyle, timeStyle, locale);
1034-
df = setJdkDateFormatFromIcu((SimpleDateFormat)dfJdk, (SimpleDateFormatICU)df);
1035-
}
1036994
df.setLenient(USE_LENIENT_MODE);
1037995
df.setTimeZone(tz);
1038996
set2DigitYearStart(df, tz);
@@ -1101,13 +1059,6 @@ public static DateFormat getLocaleInputTimeFormat(Locale locale, int style, Time
11011059
dateStyle = DateFormat.SHORT;
11021060
}
11031061
DateFormat df = getFormatProvider(locale).getTimeInstance(dateStyle, locale);
1104-
// ICU-21301 hack: Apply only with an ICU object and when timezone has DST
1105-
if (!USE_LENIENT_MODE && df instanceof SimpleDateFormatICU && tz.useDaylightTime()) {
1106-
// (re-)construct JDK's DateFormat object and copy formatting information from ICU
1107-
DateFormat dfJdk = getJDKFormatFixer().getTimeInstance(dateStyle, locale);
1108-
df = setJdkDateFormatFromIcu((SimpleDateFormat)dfJdk, (SimpleDateFormatICU)df);
1109-
}
1110-
11111062
df.setLenient(USE_LENIENT_MODE);
11121063
df.setTimeZone(tz);
11131064
set2DigitYearStart(df, tz);

src/test/java/com/force/i18n/BaseLocalizerTest.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
package com.force.i18n;
99

1010
import static org.junit.Assert.assertNotEquals;
11+
import static org.junit.Assert.assertThrows;
1112

1213
import java.text.*;
13-
import java.time.LocalDate;
1414
import java.util.*;
1515
import java.util.function.Function;
1616
import java.util.stream.Collectors;
@@ -522,11 +522,9 @@ public void test4DigitYears() {
522522
/*
523523
* ICU-21301 failed to parse the transition date (e.g. 6/9/2020 for "America/Santiago")
524524
* https://unicode-org.atlassian.net/browse/ICU-21301
525-
*
526-
* BaseLocalizer returns JDK's DateFormat object instead of ICU for particular time zone
527525
*/
528526
@Test
529-
public void testParseDateOnDST() throws Exception {
527+
public void testParseDateOnDST() {
530528
final Locale locale = Locale.GERMANY;
531529
final HumanLanguage language = HumanLanguage.Helper.get(Locale.US);
532530

@@ -536,19 +534,10 @@ public void testParseDateOnDST() throws Exception {
536534
Calendar cal = Calendar.getInstance();
537535
cal.clear();
538536

539-
BaseLocalizer icuLocalizer = new BaseLocalizer(locale, locale, TimeZone.getTimeZone("America/Santiago"), language, lSet);
540-
assertFalse(icuLocalizer.getInputDateFormat() instanceof SimpleDateFormatICU);
541-
Date date = icuLocalizer.parseDate("06.09.2020", DateFormat.SHORT);
542-
cal.setTimeZone(TimeZone.getTimeZone("America/Santiago"));
543-
cal.set(2020, 8, 6);
544-
assertEquals(cal.getTime(), date);
545-
546-
icuLocalizer = new BaseLocalizer(locale, locale, TimeZone.getTimeZone("Africa/Cairo"), language, lSet);
547-
assertFalse(icuLocalizer.getInputDateFormat() instanceof SimpleDateFormatICU);
548-
date = icuLocalizer.parseDate("26.4.2024", DateFormat.SHORT);
549-
cal.setTimeZone(TimeZone.getTimeZone("Africa/Cairo"));
550-
cal.set(2024, 3, 26);
551-
assertEquals(cal.getTime().getTime(), date.getTime());
537+
final BaseLocalizer icuLocalizer = new BaseLocalizer(locale, locale, TimeZone.getTimeZone("America/Santiago"),
538+
language, lSet);
539+
assertTrue(icuLocalizer.getInputDateFormat() instanceof SimpleDateFormatICU);
540+
assertThrows(ParseException.class, () -> icuLocalizer.parseDate("06.09.2020", DateFormat.SHORT));
552541
}
553542

554543
private static class TestSimpleIniFile extends SimpleNonConfigIniFile implements SharedLabelSet {

0 commit comments

Comments
 (0)