mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-21 12:40:02 +00:00
ICU-6669 Corrected the condition used for checking DST in time zone transition implementation in SimpleTimeZone. Also provided a test case.
X-SVN-Rev: 25185
This commit is contained in:
parent
d151bc622d
commit
4877bb6dd0
2 changed files with 36 additions and 7 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2007-2008, International Business Machines Corporation and *
|
||||
* Copyright (C) 2007-2009, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
@ -1397,6 +1397,35 @@ public class TimeZoneRuleTest extends TestFmwk {
|
|||
}
|
||||
}
|
||||
|
||||
public void TestT6669() {
|
||||
// getNext/PreviousTransition implementation in SimpleTimeZone
|
||||
// used to use a bad condition for detecting if DST is enabled or not.
|
||||
|
||||
SimpleTimeZone stz = new SimpleTimeZone(0, "CustomID",
|
||||
Calendar.JANUARY, 1, Calendar.SUNDAY, 0,
|
||||
Calendar.JULY, 1, Calendar.SUNDAY, 0);
|
||||
|
||||
long t = 1230681600000L; //2008-12-31T00:00:00
|
||||
long expectedNext = 1231027200000L; //2009-01-04T00:00:00
|
||||
long expectedPrev = 1215298800000L; //2008-07-06T00:00:00
|
||||
|
||||
TimeZoneTransition tzt = stz.getNextTransition(t, false);
|
||||
if (tzt == null) {
|
||||
errln("FAIL: No transition returned by getNextTransition.");
|
||||
} else if (tzt.getTime() != expectedNext){
|
||||
errln("FAIL: Wrong transition time returned by getNextTransition - "
|
||||
+ tzt.getTime() + " Expected: " + expectedNext);
|
||||
}
|
||||
|
||||
tzt = stz.getPreviousTransition(t, true);
|
||||
if (tzt == null) {
|
||||
errln("FAIL: No transition returned by getPreviousTransition.");
|
||||
} else if (tzt.getTime() != expectedPrev){
|
||||
errln("FAIL: Wrong transition time returned by getPreviousTransition - "
|
||||
+ tzt.getTime() + " Expected: " + expectedPrev);
|
||||
}
|
||||
}
|
||||
|
||||
// Internal utility methods -----------------------------------------
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 1996-2008, International Business Machines
|
||||
* Copyright (C) 1996-2009, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*/
|
||||
|
||||
|
@ -1182,7 +1182,7 @@ public class SimpleTimeZone extends BasicTimeZone {
|
|||
* @stable ICU 3.8
|
||||
*/
|
||||
public TimeZoneTransition getNextTransition(long base, boolean inclusive) {
|
||||
if (startMonth == 0) {
|
||||
if (!useDaylight) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1207,7 +1207,7 @@ public class SimpleTimeZone extends BasicTimeZone {
|
|||
* @stable ICU 3.8
|
||||
*/
|
||||
public TimeZoneTransition getPreviousTransition(long base, boolean inclusive) {
|
||||
if (startMonth == 0) {
|
||||
if (!useDaylight) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1234,10 +1234,10 @@ public class SimpleTimeZone extends BasicTimeZone {
|
|||
public TimeZoneRule[] getTimeZoneRules() {
|
||||
initTransitionRules();
|
||||
|
||||
int size = (startMonth == 0) ? 1 : 3;
|
||||
int size = useDaylight ? 3 : 1;
|
||||
TimeZoneRule[] rules = new TimeZoneRule[size];
|
||||
rules[0] = initialRule;
|
||||
if (startMonth != 0) {
|
||||
if (useDaylight) {
|
||||
rules[1] = stdRule;
|
||||
rules[2] = dstRule;
|
||||
}
|
||||
|
@ -1254,7 +1254,7 @@ public class SimpleTimeZone extends BasicTimeZone {
|
|||
if (transitionRulesInitialized) {
|
||||
return;
|
||||
}
|
||||
if (startMonth != 0) {
|
||||
if (useDaylight) {
|
||||
DateTimeRule dtRule = null;
|
||||
int timeRuleType;
|
||||
long firstStdStart, firstDstStart;
|
||||
|
|
Loading…
Add table
Reference in a new issue