Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Classlib
    • Labels:
      None

      Description

      The following test code gives different results on Harmony than on RI. Harmony outputs:

      d = 1143334200000

      and RI outputs:

      d = 1143337800000

      import java.text.DateFormat;
      import java.text.SimpleDateFormat;
      import java.util.TimeZone;
      import java.util.Date;
      import java.util.Locale;

      public class Test {

      public static void main(String[] args) {
      DateFormat df = new SimpleDateFormat("MMM dd, yyyy H:mm:ss.SSS",
      Locale.ENGLISH);
      TimeZone zone = TimeZone.getTimeZone("Europe/London");
      df.setTimeZone(zone);
      Date d = null;
      try

      { d = df.parse("March 26, 2006 01:50:00.000"); }

      catch (Exception e)

      { e.printStackTrace(); }

      System.err.println("d = " + d.getTime());
      }
      }

      1. harmony-493.patch
        1 kB
        Oleg Khaschansky
      2. harmony-493-test.patch
        2 kB
        Oleg Khaschansky

        Activity

        Hide
        Alexey Petrenko added a comment -

        I've modified testcase a little:

        import java.util.TimeZone;
        import java.util.Calendar;
        import java.util.Date;

        public class Jira493aTest {

        public static void main(String[] args)

        { TimeZone zone = TimeZone.getTimeZone("Europe/London"); Calendar cl = Calendar.getInstance(zone); System.err.println("Calendar class: "+cl.getClass().getName()); // d = df.parse("March 26, 2006 01:50:00.000"); cl.set(2006, 02, 26, 01, 50, 00); cl.set(Calendar.MILLISECOND, 0); System.err.println("Time: " + cl.getTimeInMillis()); System.err.println("In daylight saving?: " + zone.inDaylightTime(cl.getTime())); }


        }

        Here is a result from RI:
        Calendar class: java.util.GregorianCalendar
        Time: 1143337800000
        In daylight saving?: true

        Here is a result from Harmony:
        java version "1.5.0"
        pre-alpha : not complete or compatible
        svn = r429290, (Aug 7 2006), Windows/ia32/msvc 1310, debug build
        http://incubator.apache.org/harmony
        Calendar class: java.util.GregorianCalendar
        Time: 1143334200000
        In daylight saving?: false

        So the bug is not in SimpleDateFormat but in TimeZone and probably GregorianCalendar classes.

        Show
        Alexey Petrenko added a comment - I've modified testcase a little: import java.util.TimeZone; import java.util.Calendar; import java.util.Date; public class Jira493aTest { public static void main(String[] args) { TimeZone zone = TimeZone.getTimeZone("Europe/London"); Calendar cl = Calendar.getInstance(zone); System.err.println("Calendar class: "+cl.getClass().getName()); // d = df.parse("March 26, 2006 01:50:00.000"); cl.set(2006, 02, 26, 01, 50, 00); cl.set(Calendar.MILLISECOND, 0); System.err.println("Time: " + cl.getTimeInMillis()); System.err.println("In daylight saving?: " + zone.inDaylightTime(cl.getTime())); } } Here is a result from RI: Calendar class: java.util.GregorianCalendar Time: 1143337800000 In daylight saving?: true Here is a result from Harmony: java version "1.5.0" pre-alpha : not complete or compatible svn = r429290, (Aug 7 2006), Windows/ia32/msvc 1310, debug build http://incubator.apache.org/harmony Calendar class: java.util.GregorianCalendar Time: 1143334200000 In daylight saving?: false So the bug is not in SimpleDateFormat but in TimeZone and probably GregorianCalendar classes.
        Hide
        Oleg Khaschansky added a comment -

        The problem is that if DST transition occurs then there's an interval of invalid wall time. Say, at 1:00 DST offset changes to +1 hour. Then wall time values from 1:00 to 2:00 are invalid. RI treats such invalid time as time without DST offset, so we should follow this.

        Show
        Oleg Khaschansky added a comment - The problem is that if DST transition occurs then there's an interval of invalid wall time. Say, at 1:00 DST offset changes to +1 hour. Then wall time values from 1:00 to 2:00 are invalid. RI treats such invalid time as time without DST offset, so we should follow this.
        Hide
        Oleg Khaschansky added a comment -

        Patch for this issue.

        Show
        Oleg Khaschansky added a comment - Patch for this issue.
        Hide
        Oleg Khaschansky added a comment -

        Patch for unit test.

        Show
        Oleg Khaschansky added a comment - Patch for unit test.
        Hide
        Mark Hindess added a comment -

        Alexey/Oleg: Thanks for tracking this down.

        Oleg: I've applied the patches in r430691. Please check that I've applied it correctly.

        I'm going to re-run the Jakarta Commons Lang tests that caused me to raise this bug.

        Show
        Mark Hindess added a comment - Alexey/Oleg: Thanks for tracking this down. Oleg: I've applied the patches in r430691. Please check that I've applied it correctly. I'm going to re-run the Jakarta Commons Lang tests that caused me to raise this bug.
        Hide
        Oleg Khaschansky added a comment -

        Verified on windows/ia32.

        Show
        Oleg Khaschansky added a comment - Verified on windows/ia32.

          People

          • Assignee:
            Mark Hindess
            Reporter:
            Mark Hindess
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development