This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
// 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.
Joined: Feb 22, 2004
I get it now. Now I know why this occured only on the DST day.