1

I can't seem to figure out why joda time is updating the time and offset hours after daylight saving time, but java time doesn't.

    DateTime dateTime = new DateTime("2016-04-05T10:06:21.636-05:00").withDayOfWeek(5);

    TemporalField dayOfWeek = WeekFields.ISO.dayOfWeek();
    OffsetDateTime offsetDateTime = OffsetDateTime.parse("2016-04-05T10:06:21.636-05:00").with(dayOfWeek, 5);
    ZonedDateTime zonedDateTime = ZonedDateTime.parse("2016-04-05T10:06:21.636-05:00").with(dayOfWeek, 5);

    System.out.println("dateTime:         " + dateTime); // 2016-04-08T11:06:21.636-04:00
    System.out.println("offsetDateTime:   " + offsetDateTime); // 2016-04-08T10:06:21.636-05:00
    System.out.println("zonedDateTime:    " + zonedDateTime); // 2016-04-08T10:06:21.636-05:00
Jon
  • 453
  • 5
  • 18
  • Maybe because the java8 jsr310 implementation is close to yoda time, but not exactly the same? There are subtle differences between the two ... probably that would be one of them. – GhostCat Jul 19 '16 at 15:09
  • 2
    I guess: You did not provide a time zone, only an offset to both, the offset date time and the zoned date time instances. In both cases, they don't have any clue about daylight saving times. Probably, you must provide a time zone when constructing the zoned date time object, and it might work as you expect. – Seelenvirtuose Jul 19 '16 at 15:14
  • @Seelenvirtuose Thanks. That was the problem. – Jon Jul 19 '16 at 16:12

1 Answers1

2

Time zone versus offset

You did not provide a time zone, only an offset to both, the offset date time and the zoned date time instances. In both cases, they don't have any clue about daylight saving times as this is an information of the time zone.

So you must provide a time zone when constructing the zoned date time object, and it then it works as you expect.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Seelenvirtuose
  • 20,273
  • 6
  • 37
  • 66
  • 1
    In other words, an offset-from-UTC is merely a number of hours-minutes-seconds. A time zone is *much* more. A time zone is a history of past, present, and future changes to the offset used by the people of a particular region. – Basil Bourque Jul 09 '19 at 00:06