This is the mail archive of the
java-prs@gcc.gnu.org
mailing list for the Java project.
java/8321: SimpleTimeZone doesn't work properly for daylight saving time.
- From: dongfeng at spinnakernet dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: Wed, 23 Oct 2002 10:44:00 -0400
- Subject: java/8321: SimpleTimeZone doesn't work properly for daylight saving time.
>Number: 8321
>Category: java
>Synopsis: SimpleTimeZone doesn't work properly for daylight saving time.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Oct 23 07:46:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:
>Release: 3.1
>Organization:
>Environment:
System: Linux build2 2.4.9-12 #1 Tue Oct 30 18:33:49 EST 2001 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --host=i686-pc-linux-gnu --prefix=/home/dongfeng/gcc/temp --enable-shared --enable-threads=posix --enable-languages=c,c++,java --enable-version-specific-runtime-libs
>Description:
When I ran the folllowing code
Date date = new Date(1034705556525l);
TimeZone zone = TimeZone.getTimeZone("EST");
DateFormat dateFormat = DateFormat.getDateTimeInstance(
DateFormat.SHORT,
DateFormat.LONG,
Locale.getDefault());
dateFormat.setTimeZone(zone);
System.out.println(dateFormat.format(new Date()));
I got
10/15/2002 1:12:36 AM EST
but I expected
10/15/2002 2:12:36 AM EDT
because 10/23 is still in daylight saving time.
I checked the code of SimpleTimeZone.java. The function setEndRule
changes endDay to its absolute value that is wrong in this case. The
time zone instance for EST is
new SimpleTimeZone
(-5000 * 3600, "EST",
Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600,
Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
that has endDay -1. Turning -1 to 1 changes the end date of daylight
saving time from the last Sunday to the first Sunday in October.
The same thing happens for setStartRule.
After removing the Math.abs from the code, I got the time I want.
>How-To-Repeat:
Run above code.
>Fix:
For setStartRule, change to
this.startDay = day;
this.startDayOfWeek = dayOfWeek;
For setEndRule,change to
this.endDay = day;
this.endDayOfWeek = dayOfWeek;
>Release-Note:
>Audit-Trail:
>Unformatted: