Uploaded image for project: 'Directory Client API'
  1. Directory Client API
  2. DIRAPI-336

GeneralizedTime issue with timezone when DST is applied

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.0.0.AM2
    • 2.0.0.AM3
    • None
    • Windows 10 pro
      JDK 1.8.0_144
      api-util 2.0.0.AM2

    Description

      I have been facing some issues with timezone when I use GeneralizedTime. Looks like GeneralizedTime is not taking into account DST (daylight saving time) have taken place in Europe.

      After the last Sunday in March DST is applied in most European countries. I expect to see +0200 timezone offset when the date in April is converted to the string, but there is a +0100 (line 4 in output section).

      I have pasted a following code snippet, where I write date with time and timezone offset to the output from ZonedDateTime and GeneralizedTime.

       

      import org.apache.directory.api.util.GeneralizedTime;
      
      import java.text.SimpleDateFormat;
      import java.time.LocalDateTime;
      import java.time.ZoneId;
      import java.time.ZonedDateTime;
      import java.util.GregorianCalendar;
      
      
      ZoneId swissZone = ZoneId.of("Europe/Zurich");
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssZ");
      
      ZonedDateTime winterZonedDateTime = LocalDateTime.parse("2019-01-23T01:23:45").atZone(swissZone);
      GregorianCalendar winterCalendar = GregorianCalendar.from(winterZonedDateTime);
      System.out.println(dateFormat.format(winterCalendar.getTime()));    // 20190123012345+0100
      
      GeneralizedTime winterGeneralizedTime = new GeneralizedTime(winterCalendar);
      String winterGeneralizedTimeString = winterGeneralizedTime.toGeneralizedTime(
              GeneralizedTime.Format.YEAR_MONTH_DAY_HOUR_MIN_SEC,
              GeneralizedTime.FractionDelimiter.DOT, 1,
              GeneralizedTime.TimeZoneFormat.DIFF_HOUR_MINUTE);
      System.out.println(winterGeneralizedTimeString);    // 20190123012345+0100
      
      ZonedDateTime summerZonedDateTime = LocalDateTime.parse("2019-04-03T01:23:45").atZone(swissZone);
      GregorianCalendar summerCalendar = GregorianCalendar.from(summerZonedDateTime);
      System.out.println(dateFormat.format(summerCalendar.getTime()));    // 20190403012345+0200
      
      GeneralizedTime summerGeneralizedTime = new GeneralizedTime(summerCalendar);
      String summerGeneralizedTimeString = summerGeneralizedTime.toGeneralizedTime(
              GeneralizedTime.Format.YEAR_MONTH_DAY_HOUR_MIN_SEC,
              GeneralizedTime.FractionDelimiter.DOT, 1,
              GeneralizedTime.TimeZoneFormat.DIFF_HOUR_MINUTE);
      System.out.println(summerGeneralizedTimeString);    // 20190403012345+0100
      
      

       The output is

      20190123012345+0100 // winter time from ZonedDateTime 
      20190123012345+0100 // winter time from GeneralizedTime 
      20190403012345+0200 // summer time from ZonedDateTime 
      20190403012345+0100 // summer time from GeneralizedTime, expected timezone offset +0200
      

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            vitali.sidaruk Vitali Sidaruk
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: