diff options
-rw-r--r-- | luni/src/main/java/org/apache/harmony/luni/internal/util/ZoneInfo.java | 17 | ||||
-rw-r--r-- | luni/src/test/java/tests/api/java/util/TimeZoneTest.java | 13 |
2 files changed, 27 insertions, 3 deletions
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/util/ZoneInfo.java b/luni/src/main/java/org/apache/harmony/luni/internal/util/ZoneInfo.java index 110a0fd..01319e1 100644 --- a/luni/src/main/java/org/apache/harmony/luni/internal/util/ZoneInfo.java +++ b/luni/src/main/java/org/apache/harmony/luni/internal/util/ZoneInfo.java @@ -111,12 +111,23 @@ public class ZoneInfo extends TimeZone { // Subtract the raw offset from all offsets so it can be changed // and affect them too. - // Find whether there exist any observances of DST. - for (int i = 0; i < mGmtOffs.length; i++) { mGmtOffs[i] -= mRawOffset; + } - if (mIsDsts[i] != 0) { + // Is this zone still observing DST? + // We don't care if they've historically used it: most places have at least once. + // We want to know whether the last "schedule info" (the unix times in the mTransitions + // array) is in the future. If it is, DST is still relevant. + // See http://code.google.com/p/android/issues/detail?id=877. + // This test means that for somewhere like Morocco, which tried DST in 2009 but has + // no future plans (and thus no future schedule info) will report "true" from + // useDaylightTime at the start of 2009 but "false" at the end. This seems appropriate. + long currentUnixTime = System.currentTimeMillis() / 1000; + if (mTransitions.length > 0) { + // (We're really dealing with uint32_t values, so long is most convenient in Java.) + long latestScheduleTime = mTransitions[mTransitions.length - 1] & 0xffffffff; + if (currentUnixTime < latestScheduleTime) { mUseDst = true; } } diff --git a/luni/src/test/java/tests/api/java/util/TimeZoneTest.java b/luni/src/test/java/tests/api/java/util/TimeZoneTest.java index efdb8a1..75e9ae3 100644 --- a/luni/src/test/java/tests/api/java/util/TimeZoneTest.java +++ b/luni/src/test/java/tests/api/java/util/TimeZoneTest.java @@ -383,6 +383,19 @@ public class TimeZoneTest extends junit.framework.TestCase { @TestTargetNew( level = TestLevel.COMPLETE, notes = "", + method = "useDaylightTime", + args = {} + ) + public void test_useDaylightTime() { + // http://code.google.com/p/android/issues/detail?id=877 + + TimeZone asiaTaipei = TimeZone.getTimeZone("Asia/Taipei"); + assertFalse("Taiwan doesn't use DST", asiaTaipei.useDaylightTime()); + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", method = "setID", args = {java.lang.String.class} ) |