Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Possble Calendar bug with daylight saving time

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 26951
83
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I get it now. Now I know why this occured only on the DST day.

Thanks!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic