summaryrefslogtreecommitdiff
path: root/icu4j/main/tests
diff options
context:
space:
mode:
authorVictor Chang <vichang@google.com>2019-05-02 16:39:56 +0100
committerVictor Chang <vichang@google.com>2019-05-02 19:29:38 +0100
commit35bf71735aebc25a250a9124221dbae91b30d83d (patch)
tree8bcc24bdabb4a9b612ca43bd1e0c40f00efd7040 /icu4j/main/tests
parenta2c2903f404bb4175173292be39b83f5558d62b9 (diff)
downloadicu-35bf71735aebc25a250a9124221dbae91b30d83d.tar.gz
JapaneseCalendar.CURRENT_ERA should not depend on system time
JapaneseCalendar.CURRENT_ERA is static final int. Since ICU 63, CURRENT_ERA is computed based on the system time, via the API System.currentTimeMillis(). Before ICU 63 (Android P or below), it takes the latest era known by ICU. Android could initialize the value early during boot with an incorrect system time, and could result in undesired behavior in app, e.g. using the previous era Heisei in date format, even though the system time is set to a time in Reiwa era. This change set JapaneseCalendar.CURRENT_ERA to REIWA, which is the latest era known to ICU. Also fix android.icu.dev.test.calendar.EraRulesTest#testAPIs test failure during the era transition due to time zone inconsistency in the test. Note on JapaneseTest#Test3860, it passes on before and after era starts, even though it depends on CURRENT_ERA in the test. Bug: 131822957 Bug: 131766004 Test: CtsIcuTestCases when system time is to 30 Apr, 1 May(UTC) and 2 may Change-Id: I0b1bdba23ebf2c61d6627d920a9610cf47327405
Diffstat (limited to 'icu4j/main/tests')
-rw-r--r--icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/EraRulesTest.java4
1 files changed, 3 insertions, 1 deletions
diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/EraRulesTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/EraRulesTest.java
index c2cf6e11d..7a1e6fcf8 100644
--- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/EraRulesTest.java
+++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/EraRulesTest.java
@@ -12,6 +12,7 @@ import com.ibm.icu.impl.EraRules;
import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.JapaneseCalendar;
import com.ibm.icu.util.ULocale;
+import com.ibm.icu.util.TimeZone;
/**
* Tests for EraRules class
@@ -44,7 +45,8 @@ public class EraRulesTest extends TestFmwk {
+ calId);
}
- Calendar cal = Calendar.getInstance(new ULocale("en"));
+ // Android-changed: EraRules.getCurrentEraIndex() uses UTC time. http://b/131766004
+ Calendar cal = Calendar.getInstance(TimeZone.GMT_ZONE, new ULocale("en"));
int currentIdx = rules1.getCurrentEraIndex();
int currentYear = cal.get(Calendar.YEAR);
int idx = rules1.getEraIndex(currentYear, cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DATE));