Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-916

CLONE - DateFormatUtils.format does not correctly change Calendar TimeZone in certain situations

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.1
    • 3.5
    • lang.time.*
    • Sun JDK 1.6.0_45 and 1.7.0_21 on Fedora 17 (Linux 3.9.10-100.fc17.i686.PAE).

    Description

      In LANG-538 issue, there is an unit test:

        public void testFormat_CalendarIsoMsZulu() {
          final String dateTime = "2009-10-16T16:42:16.000Z";
          GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT-8"));
          cal.clear();
          cal.set(2009, 9, 16, 8, 42, 16);
          cal.getTime();
      
          FastDateFormat format = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", TimeZone.getTimeZone("GMT"));
          assertEquals("dateTime", dateTime, format.format(cal));
        }
      

      This test passes successfully in lang-2.6 but failed in lang3-3.1:

      org.junit.ComparisonFailure: dateTime expected:<2009-10-16T[16]:42:16.000Z> but was:<2009-10-16T[08]:42:16.000Z>
      

      Reproduced whit Sun Java version: 1.6.0_45 and 1.7.0_21 on Fedora 17 (Linux 3.9.10-100.fc17.i686.PAE).

      Moreover, I wrote another unit test showing that the timeZone parameter seems to be ignored :

      public void test() {
      	Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Europe/Paris"));
      	cal.set(2009, 9, 16, 8, 42, 16);
      
      	// System.out.println(DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(cal));
      
      	System.out.println("long");
      	System.out.println(DateFormatUtils.format(cal.getTimeInMillis(), DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getDefault()));
      	System.out.println(DateFormatUtils.format(cal.getTimeInMillis(), DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(),
      			TimeZone.getTimeZone("Asia/Kolkata")));
      	System.out.println(DateFormatUtils.format(cal.getTimeInMillis(), DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(),
      			TimeZone.getTimeZone("Europe/London")));
      
      	System.out.println("calendar");
      	System.out.println(DateFormatUtils.format(cal, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getDefault()));
      	System.out.println(DateFormatUtils.format(cal, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone("Asia/Kolkata")));
      	System.out.println(DateFormatUtils.format(cal, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone("Europe/London")));
      
      	System.out.println("calendar fast");
      	System.out.println(FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", TimeZone.getTimeZone("Europe/Paris")).format(cal));
      	System.out.println(FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", TimeZone.getTimeZone("Asia/Kolkata")).format(cal));
      	System.out.println(FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", TimeZone.getTimeZone("Europe/London")).format(cal));
      }
      

      Gives the following console logs:

      long
      2009-10-16T08:42:16+02:00
      2009-10-16T12:12:16+05:30
      2009-10-16T07:42:16+01:00
      calendar
      2009-10-16T08:42:16+02:00
      2009-10-16T08:42:16+02:00
      2009-10-16T08:42:16+02:00
      calendar fast
      2009-10-16T08:42:16.975Z
      2009-10-16T08:42:16.975Z
      2009-10-16T08:42:16.975Z
      

      When DateFormatUtils.format takes a long parameter, the time string is good.
      When DateFormatUtils.format takes a Calendar parameter, the time string is wrong, the timezone parameter is IGNORED.

      Attachments

        1. LANG-916-final-git.patch
          5 kB
          Christian P. MOMON
        2. LANG-916-C.patch
          3 kB
          Christian P. MOMON
        3. LANG-916-B.patch
          0.8 kB
          Christian P. MOMON
        4. LANG-916.patch
          0.6 kB
          Thomas Neidhart

        Issue Links

          Activity

            People

              chonton Charles Honton
              cpm Christian P. MOMON
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: