summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2014-09-12 15:01:52 +0100
committerNeil Fuller <nfuller@google.com>2014-09-15 17:29:20 +0100
commit788b5e43bc025b6aaa144e6483c744729528e79b (patch)
tree5befdf061c77ff4d2a5b721e5cbc9a116af02712
parente3c2ce0b26d1698929651380577afe11c71a465d (diff)
downloadlibcore-788b5e43bc025b6aaa144e6483c744729528e79b.zip
libcore-788b5e43bc025b6aaa144e6483c744729528e79b.tar.gz
libcore-788b5e43bc025b6aaa144e6483c744729528e79b.tar.bz2
Fix ZoneInfo.useDaylightTime()
Currently implemented is "are there any offset transitions in the future?". This is wrong: Transitions may occur in the future because of DST, but can also occur for other reasons (e.g. if the raw offset for a zone changes). We should be implementing: Is the currently active transition, or any transition in the future, one that has isDst == true. This was causing a test failure in libcore.java.util.TimeZoneTest#testDisplayNames for Asia/Novokuznetsk and Europe/Simferopol for tzdata2014g. This is because they have a transition entry for October 26, 2014 (i.e. in the future). For each, the existance of the transition entry is not due to an offset change at all: For Asia/Novokuznetsk it is because the abbreviation for the zone changes on that date (information we don't curently use). For Europe/Simferopol it is because the offset from UTC changes on that date (but there is no actual DST transtion). Bug: 17377276 (cherry-picked from commit d42af6ed0fec3cfca52912b0d8b3b459e72be4b4) Change-Id: I148503280b8dee653bac32eec3aa58d232102628
-rw-r--r--luni/src/main/java/libcore/util/ZoneInfo.java15
1 files changed, 7 insertions, 8 deletions
diff --git a/luni/src/main/java/libcore/util/ZoneInfo.java b/luni/src/main/java/libcore/util/ZoneInfo.java
index fbd120b..4a70a83 100644
--- a/luni/src/main/java/libcore/util/ZoneInfo.java
+++ b/luni/src/main/java/libcore/util/ZoneInfo.java
@@ -156,22 +156,21 @@ public final class ZoneInfo extends TimeZone {
mOffsets[i] -= mRawOffset;
}
- // Is this zone still observing DST?
+ // Is this zone observing DST currently or in the future?
// 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.
boolean usesDst = false;
- 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 = ((long) mTransitions[mTransitions.length - 1]) & 0xffffffff;
- if (currentUnixTime < latestScheduleTime) {
+ int currentUnixTimeSeconds = (int) (System.currentTimeMillis() / 1000);
+ int i = mTransitions.length - 1;
+ while (i >= 0 && mTransitions[i] >= currentUnixTimeSeconds) {
+ if (mIsDsts[mTypes[i]] > 0) {
usesDst = true;
+ break;
}
+ i--;
}
mUseDst = usesDst;