Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4475205

GregorianCalendar.getTime() fails in server mode

    XMLWordPrintable

Details

    Description



      Name: dfR10049 Date: 06/27/2001



      java.util.GregorianCalendar incorrectly works in server mode with
      some TimeZones and Locales. The output of getTime() is different
      for the same date in different modes.

      This is the test demonstrating the bug:
      ------------------------------------------------------------------
      import java.util.*;

      public class TZ {

          public static void main (String args[]){

              long day = 1000*60*60*24;
              Date d = new Date(-5000*day);
              System.out.println("Date: " + d);

              String[] ids = TimeZone.getAvailableIDs();
              Locale[] locales = Locale.getAvailableLocales();
              for (int i = 0; i < ids.length; i++) {
                  TimeZone tz = TimeZone.getTimeZone(ids[i]);
                  TimeZone.setDefault(tz);

                  for (int j = 0; j < locales.length; j++) {
                      Locale loc = locales[j];
                      Locale.setDefault(loc);

                      GregorianCalendar calendar = new GregorianCalendar(tz, loc);
                      calendar.setTime(d);
                      if ( calendar.get(Calendar.DAY_OF_MONTH) < 23) {
                          System.out.println("Test failed with ");
                          System.out.println(" TimeZone: " + tz);
                          System.out.println(" Locale: " + loc);
                          System.out.println(" date: " + calendar.getTime());
                          return;
                      }
                  }
              }
              System.out.println("Test passed");
          }
      }
      ---------------------------------------------------------------------
      output from the test:

      #> java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)

      #> java TZ
      Date: Tue Apr 24 03:00:00 GMT+03:00 1956
      Test passed

      #> java -server TZ
      Date: Tue Apr 24 03:00:00 GMT+03:00 1956
      Test failed with
          TimeZone: sun.util.calendar.ZoneInfo[id="America/Adak",offset=-36000000,dstSavings=3600000,useDaylight=true,transitions=142,lastRule=java.util.SimpleTimeZone[id=America/Adak,offset=-36000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=3,startDay=1,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]
          Locale: fr_FR
          date: Mon Apr 10 13:00:00 HAST 1956

      ======================================================================

      Attachments

        Activity

          People

            peytoia Yuka Kamiya (Inactive)
            fdasunw Fda Fda (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: