wood burning stoves 2.0*
The moose likes Java in General and the fly likes Possble Calendar bug with daylight saving time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Possble Calendar bug with daylight saving time" Watch "Possble Calendar bug with daylight saving time" New topic
Author

Possble Calendar bug with daylight saving time

Dan Howard
Ranch Hand

Joined: Feb 22, 2004
Posts: 47
So my cell phone rings this morning early and it's support calling to tell me that users are reporting strange errors in the application. When I have a look I find the problem is that we're comparing a date submitted via a web form to a date previously stored. The date submitted is in the format YYYYMMDDhhmm and it looks good though when I debug and look at the Calendar object created from this string it's an hour ahead!

Somehow on DST days the clock is being pushed up one more hour than it should. This is on a Windows machine in a DST time zone (for me Montreal Eastern Standard Time).

Below is a simple program to demonstrate this problem. It seems that the Calendar add method is the culprit. If I create a calendar by setting just the date and then 'adding' the minutes it bumps an hour up. If I just set each Calendar field it works fine.

Anyone want to confirm this? This is java 5_07 and java 6. TIA.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

// Calculate the minutes in the day from 1102 AM = 662 minutes from midnight
This is incorrect on a day when DST starts. The answer in this case is 602 minutes because the second after 1:59:59 was 3:00:00. So if you are saying your calculations don't come out to 662 minutes, that isn't a bug in the Calendar class. It's the way it's supposed to be.
Dan Howard
Ranch Hand

Joined: Feb 22, 2004
Posts: 47
I get it now. Now I know why this occured only on the DST day.

Thanks!
 
jQuery in Action, 2nd edition
 
subject: Possble Calendar bug with daylight saving time
 
Similar Threads
Java util Date & Calendar - 1900 years
add one day to current date
Calculating days between two dates
Holiday in date
Convert date time to file date time