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

Calendar gives wrong time on 01.01.1900 for some african time zones

    Details

      Description

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      Setting the day time in millis on 01.01.1900 gives very strange results: for time range between 02:00:00 and 02:10:00 a Calendar instance uses an "10 min 10 sec"-offset, so setting the time to 02:00:00 gives 02:10:20 in output and so on as shown below:
      02:00:00 -> 02:10:20
      02:01:00 -> 02:11:20
      02:02:00 -> 02:12:20
      02:03:00 -> 02:13:20
      02:04:00 -> 02:14:20
      02:05:00 -> 02:15:20
      02:06:00 -> 02:16:20
      02:07:00 -> 02:17:20
      02:08:00 -> 02:18:20
      02:09:00 -> 02:19:20
      02:10:00 -> 02:20:20
      But this is so only for some african time zones, such as CAT, Africa/Abidjan etc.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.Calendar;
      import java.text.DateFormat;
      import java.text.SimpleDateFormat;
      import java.util.Calendar;
      import java.util.TimeZone;

      public class HelloWorld
      {

        public static void main(String[] args)
        {
          for(String tzId : TimeZone.getAvailableIDs()) {
            TimeZone tz = TimeZone.getTimeZone(tzId);

            DateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
            sdf.setTimeZone(tz);

            Calendar c1 = Calendar.getInstance(tz);
            Calendar c2 = Calendar.getInstance(tz);

            c1.set(1900, 0, 1, 0, 0, 0);
            c2.set(1900, 0, 1, 0, 0, 0);

            c1.set(Calendar.MILLISECOND, 7573000); // 02:06:13
            c2.set(Calendar.MILLISECOND, 8193000); // 02:16:33

            String f1 = sdf.format(c1.getTime());
            String f2 = sdf.format(c2.getTime());

            if(f1.equals(f2)) {
              System.out.println(tzId);
              System.out.println(f1);
              System.out.println(f2);
              System.out.println("");
            }

          }
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Using any "working" time zone (UTC,...) solves this problem.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                naoto Naoto Sato
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: