-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.2.0
-
sparc
-
solaris_2.5
Name: avC70361 Date: 07/21/98
The java.util.SimpleTimeZone.getOffset works wrong when its time zone end rule is just after
a midnight of a day and getOffset parameters represent a day which is just after the end rule date.
The getOffset method returns a wrong offset which is appropriate to DST period.
Here is a test demonstrating the bug.
------------GetOffsetTest.java---------------
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.SimpleTimeZone;
import java.util.TimeZone;
public class GetOffsetTest {
public static void main(String args[]) {
SimpleTimeZone tz = new SimpleTimeZone(
60 * 60 * 1000, "MyTimeZone",
Calendar.JANUARY, 1, 0, 0, /* DST start day: January, 1, 0:00 */
Calendar.APRIL, 1, 0, 0, /* DST end day: April, 1, 0:00 */
60 * 60 * 1000
);
Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
// setting a date using GMT zone just after the end rule of tz zone
calendar.clear();
calendar.set(Calendar.ERA, GregorianCalendar.AD);
calendar.set(Calendar.YEAR, 1998);
calendar.set(Calendar.MONTH, Calendar.MARCH);
calendar.set(Calendar.DATE, 31);
calendar.set(Calendar.HOUR, 22);
calendar.set(Calendar.MINUTE, 1);
Date date = calendar.getTime();
int millis = calendar.get(Calendar.HOUR_OF_DAY) * 3600000
+ calendar.get(Calendar.MINUTE) * 60000
+ calendar.get(Calendar.SECOND) * 1000
+ calendar.get(Calendar.MILLISECOND)
/* we should use standard local time */
+ tz.getRawOffset();
int offset = tz.getOffset(
calendar.get(Calendar.ERA),
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DATE),
calendar.get(Calendar.DAY_OF_WEEK),
millis
);
SimpleDateFormat format = new SimpleDateFormat("dd MMM HH:mm:ss zzz", Locale.US);
format.setTimeZone(tz);
System.out.println("time zone = " + tz);
System.out.println("a date just after DST = " + format.format(date));
System.out.println("getOffset = " + offset);
}
}
--------------The test output------------
> java -version
java version "1.2beta4"
Classic VM (build JDK-1.2beta4-K, green threads, sunwjit)
> java GetOffsetTest
time zone = java.util.SimpleTimeZone[id=MyTimeZone,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=1,startMonth=0,startDay=1,startDayOfWeek=0,startTime=0,endMode=1,endMonth=3,endDay=1,endDayOfWeek=0,endTime=0]
a date just after DST = 01 Apr 00:01:00 GMT+02:00
getOffset = 7200000
======================================================================
- duplicates
-
JDK-4162593 TimeZone broken at MIDNIGHT
-
- Closed
-