diff options
author | Elliott Hughes <enh@google.com> | 2009-09-22 13:27:24 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2009-09-22 13:27:24 -0700 |
commit | 8ed4ad0c5b361f7a196eb97bc3ec210ab086623b (patch) | |
tree | f3265d616294ddd8ae06b96904543eaf69b10525 /luni | |
parent | ad1af8e17368582b24fd9e2b6e2b2578ab4d8829 (diff) | |
download | libcore-8ed4ad0c5b361f7a196eb97bc3ec210ab086623b.zip libcore-8ed4ad0c5b361f7a196eb97bc3ec210ab086623b.tar.gz libcore-8ed4ad0c5b361f7a196eb97bc3ec210ab086623b.tar.bz2 |
Fix useDaylightTime for zh_TW (and other locales).
TimeZone.useDaylightTime shouldn't report whether a locale has *ever* used DST,
but whether a locale uses DST "these days". Taiwan is an example supported
locale that historically used DST but hasn't used it since 1980.
Bug: 877
Diffstat (limited to 'luni')
-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} ) |