From 3d19a928e77e1db3ae4bd4e991b57af7818b22a5 Mon Sep 17 00:00:00 2001 From: yumaoka Date: Wed, 3 Apr 2019 14:58:45 -0400 Subject: [PATCH] ICU-20475 Japanese calendar era calculation should use local time, not UTC (ICU4J) --- .../classes/core/src/com/ibm/icu/impl/EraRules.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/EraRules.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/EraRules.java index 9b82396fc86..36835bd4706 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/EraRules.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/EraRules.java @@ -5,6 +5,7 @@ package com.ibm.icu.impl; import java.util.Arrays; import com.ibm.icu.util.ICUException; +import com.ibm.icu.util.TimeZone; import com.ibm.icu.util.UResourceBundle; import com.ibm.icu.util.UResourceBundleIterator; @@ -201,7 +202,8 @@ public class EraRules { /** * Gets the current era index. This is calculated only once for an instance of - * EraRules. + * EraRules. The current era calculation is based on the default time zone at + * the time of instantiation. * * @return era index of current era (or 0, when current date is before the first era) */ @@ -210,7 +212,11 @@ public class EraRules { } private void initCurrentEra() { - int[] fields = Grego.timeToFields(System.currentTimeMillis(), null); + long localMillis = System.currentTimeMillis(); + TimeZone zone = TimeZone.getDefault(); + localMillis += zone.getOffset(localMillis); + + int[] fields = Grego.timeToFields(localMillis, null); int currentEncodedDate = encodeDate(fields[0], fields[1] + 1 /* changes to 1-base */, fields[2]); int eraIdx = numEras - 1; while (eraIdx > 0) {