3 Replies Latest reply: Mar 9, 2013 12:44 PM by rukbat RSS

    Issue with GregorianCalendar class

    813322
      The below snippet of code shows the following output:

      Sat Apr 01 02:00:00 EST 2000
      Sat Apr 01 04:00:00 EST 2000
      Sat Apr 01 06:00:00 EST 2000
      Sat Apr 01 08:00:00 EST 2000
      Sat Apr 01 10:00:00 EST 2000
      Sat Apr 01 12:00:00 EST 2000
      Sat Apr 01 14:00:00 EST 2000
      Sat Apr 01 16:00:00 EST 2000
      Sat Apr 01 18:00:00 EST 2000
      Sat Apr 01 20:00:00 EST 2000
      Sat Apr 01 22:00:00 EST 2000
      Sun Apr 02 00:00:00 EST 2000
      Sun Apr 02 03:00:00 EDT 2000 //Shouldn't this be 'Sun Apr 02 02:00:00 EDT 2000' Each loop adds 2 hours (120 minutes)
      Sun Apr 02 05:00:00 EDT 2000
      Sun Apr 02 07:00:00 EDT 2000

      The output inexplicably jumps from 'Sun Apr 02 00:00:00 EST 2000' to 'Sun Apr 02 03:00:00 EDT 2000'. If each loop adds 120 minutes (2 hours) to the previous date hold by cal, what is triggering this jump?




      ****************************

      GregorianCalendar cal;
      int dt=120; //to add 120 minutes (two hours in each loop)


      cal = new GregorianCalendar(2000,3,1,0,0,0);

      for(int i=0;i<15;i++)
      {    cal.add(Calendar.MINUTE,dt);
      System.out.println(cal.getTime());
      }



      ***************************
        • 1. Re: Issue with GregorianCalendar class
          rukbat
          Sat Apr 01 22:00:00 EST 2000
          Sun Apr 02 00:00:00 EST 2000
          Sun Apr 02 03:00:00 EDT 2000 //Shouldn't this be 'Sun Apr 02 02:00:00 EDT 2000' Each loop adds 2 hours (120 minutes)
          Sun Apr 02 05:00:00 EDT 2000
          When did Daylight Savings Time take effect for your computer system, for that calendar year that you are manipulating?
          • 2. Re: Issue with GregorianCalendar class
            813322
            Thanks for your response. My computer time is currently set to year 2013, year for which Daylight Savings time take effect (tonight USA Eastern Time)
            • 3. Re: Issue with GregorianCalendar class
              rukbat
              I was only trying to suggest that the locale for the system may be interpreting the DST rules for the calendar year 2000 specifically, while the task was running. The DST rules for 2k were different than they are now. The jump forward at 2AM was in April in 2000, whereas it's in March currently. That modification occurred in 2007.
              http://en.wikipedia.org/wiki/Daylight_savings_time#Procedure

              We'll next leave this thread for others to contribute.