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

ZonedDateTime is not working as expected for Brazil (unrelated to JDK version)

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Linux, open jdk8u242

      A DESCRIPTION OF THE PROBLEM :
      We are already using jdk version (8u242) that respects the latest timezone schedule for Brazil.

      We are seeing a very weird issue happened only on DST transition date in Brazil, and only on the time when this transition happened

      E.g.
      1. for ZonedDateTime - 2018/11/03/00:00:00 in timezone "America/Sao_Paulo", if plus one day, it will return us 2018/11/04/01:00:00, you can see the hour is changed, this is not ideal
      2. but if I set an hour, like 2018/11/03/01:00:00, after plus 1 day, it will return 2018/11/04/01:00:00 as expected
      3. I tried the same thing with US timezone, it works as expected no matter the start time is right on the transition time (2 am) or other time, I also tried past years besides 2020, they all works as expected (i.e. plus one day without changing the hour)




      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Included source code below

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      for 2018-11-04 it should printout 2018-11-04T00:00-02:00[America/Sao_Paulo]
      for 2017-10-15 it should printout 2017-10-15T00:00-02:00[America/Sao_Paulo]
      ACTUAL -
      2018-11-03T00:00-03:00[America/Sao_Paulo]
      2018-11-04T01:00-02:00[America/Sao_Paulo]
      2019-02-16T00:00-02:00[America/Sao_Paulo]
      2019-02-17T00:00-03:00[America/Sao_Paulo]
      2017-10-14T00:00-03:00[America/Sao_Paulo]
      2017-10-15T01:00-02:00[America/Sao_Paulo]
      2018-02-17T00:00-02:00[America/Sao_Paulo]
      2018-02-18T00:00-03:00[America/Sao_Paulo]
      2020-11-01T00:00-04:00[America/New_York]
      2020-11-02T00:00-05:00[America/New_York]

      ---------- BEGIN SOURCE ----------
      import java.time.LocalDateTime;
      import java.time.ZoneId;
      import java.time.ZonedDateTime;
      import java.time.temporal.ChronoUnit;
      import java.util.TimeZone;

      public static void main(String[] args) {
          ZoneId zone = TimeZone.getTimeZone("America/Sao_Paulo").toZoneId();
          ZonedDateTime time1 = ZonedDateTime.of(LocalDateTime.of(2018, 11, 3, 0, 0),zone);
          System.out.println(time1);
          ZonedDateTime time2 = time1.plus(1, ChronoUnit.DAYS);
          System.out.println(time2);

          ZonedDateTime time3 = ZonedDateTime.of(LocalDateTime.of(2019, 2, 16, 0, 0),zone);
          System.out.println(time3);
          ZonedDateTime time4 = time3.plus(1, ChronoUnit.DAYS);
          System.out.println(time4);

          ZonedDateTime time5 = ZonedDateTime.of(LocalDateTime.of(2017, 10, 14, 0, 0),zone);
          System.out.println(time5);
          ZonedDateTime time6 = time5.plus(1, ChronoUnit.DAYS);
          System.out.println(time6);

          ZonedDateTime time7 = ZonedDateTime.of(LocalDateTime.of(2018, 2, 17, 0, 0),zone);
          System.out.println(time7);
          ZonedDateTime time8 = time7.plus(1, ChronoUnit.DAYS);
          System.out.println(time8);

          ZonedDateTime time9 = ZonedDateTime.of(LocalDateTime.of(2020, 11, 1, 0, 0),TimeZone.getTimeZone("America/New_York").toZoneId());
          System.out.println(time9);
          ZonedDateTime time10 = time9.plus(1, ChronoUnit.DAYS);
          System.out.println(time10);
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      We have to truncate the date so it will return midnight time for us instead of 1am in Brazil

        Attachments

          Activity

            People

            • Assignee:
              kravikumar Kiran Sidhartha Ravikumar
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: