Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
February 09, 2012, 03:59:15 PM

Pages: [1]   Go Down
  Print  
Author Topic: Java calendar issue on 10/31?  (Read 1842 times)
mjnoonan
Intergalactic Cowboy
*****
Offline Offline

Posts: 74


« on: October 31, 2009, 11:39:14 AM »

I just saw something very strange with a Java servlet I've been running for at least 5 years now with no similar issue.  It uses the Java Calendar object to calculate if a given date and time has passed (once a week) and does some processing if the time has passed.  Today I saw it think that 10/31/09 12:45pm was later than 11/1/09 12:45pm so it did stuff that wasn't supposed to happen until tomorrow!  I checked my logs and it appears that the time on the server is correct so I don't believe this is a LunarPages issue (although I'll open a ticket to see if they know of any Java bug that might cause this).  Has anyone heard anything like this or had the same type of thing occur to them?  Possibly related to the change of the Daylight Savings Time date - I don't see how.  But like I said, this site has been running with no issues for over 5 years and I've never seen this happen!
Logged
mjnoonan
Intergalactic Cowboy
*****
Offline Offline

Posts: 74


« Reply #1 on: October 31, 2009, 12:06:10 PM »

I believe I've confirmed this bug in Java.  I wrote some quick code that is similar to how the site figures out if a deadline has passed:

        TimeZone tz = TimeZone.getTimeZone("US/Eastern");
        Calendar deadCal = Calendar.getInstance(tz);
        deadCal.set(2009, 11, 1, 12, 45);           

        // curr time to Calendar
        Calendar currCal = Calendar.getInstance(tz);
        currCal.set(2009, 10, 31, 12, 46);
       
        if (deadCal.before(currCal))
        {
           int x = 0;
           x++;
        }

This sets the deadline to 11/1/2009 12:45PM and sets the current time to 10/31/09 12:46PM.  This should not trigger the if statement but does.  If I change the deadline date to 12/1/09 12:45PM and the current date to 11/30/09 12:46PM it does not trigger the if clause.   Guess I need to report this to the Java folks.
Logged
mjnoonan
Intergalactic Cowboy
*****
Offline Offline

Posts: 74


« Reply #2 on: October 31, 2009, 01:38:13 PM »

Funny, I did some more testing and the next 5 years when we switch to Daylight Savings Time I cannot duplicate the issue.  But in 2015 when we again switch on 11/1, lo and behold, the same issue manifests itself.  Must be the combo of the switchover plus the month change the same day.
Logged
jackbc
Pong! (the videogame) Master
*****
Offline Offline

Posts: 21


WWW
« Reply #3 on: November 03, 2009, 07:54:38 AM »

Not sure if you have figured out the problem yet, but I had a similar problem a year or two ago when the rules for daylight savings time changed.

Do you know what java version is running on your server?
If it is older than 1.4.2_11, it has the old DST rules. There is a patch that updates the rules (TZUpdater tool from Sun) that needs to be run on the server.

In my case, rather then applying the patch, Lunarpages just move me to a newer server with Java 5.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to: