Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Possble Calendar bug with daylight saving time

 
Dan Howard
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21152
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
// 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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get it now. Now I know why this occured only on the DST day.

Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic