ZonedDateTime.plusHours() #160

Closed
jodastephen opened this Issue Nov 29, 2012 · 5 comments

Comments

Projects
None yet
3 participants
Owner

jodastephen commented Nov 29, 2012

What behaviour should ZonedDateTime.plusHours() have?

ZonedDateTime.plusDays() operates on the local time-line, resolving any result in a gap to an appropriate answer. This is the same as Joda-Time.

Currently, ZonedDateTime.plusHours() also operates on the local time-line, however Joda-Time operates on the instant time-line. If there is a gap from 01:00 to 02:00 then:

dt = ... // 00:30 just before a DST gap

// Joda-Time
dt = dt.plusHours(2)    // results in 03:30  (2 "real" hours later)
dt = dt.plusHours(1)    // results in 02:30  (1 "real" hour later)
dt = dt.plusHours(24)   // results in 01:30 +P1D  (24 "real" hours later)

// Current 310
dt = dt.plusHours(2)    // results in 02:30  (2 local hours later, but only 1 "real" hour)
dt = dt.plusHours(1)    // results in 01:30 which is adjusted to 02:30
dt = dt.plusHours(24)   // results in 00:30 +P1D  (24 local hours later, but only 23 "real" hours)

My gut feel is that more people want the Joda-Time way, where days are added locally, but time is added exactly (by duration). Making the change would also affect Period, and would mean that Duration no longer had any special logic for doing addition. Clearly however, this would mean period calculations for date and times would operate differently.

Owner

jodastephen commented Nov 29, 2012

Even if this change is not made, there is a bug in the current implementation. Calling plusHours(1) on a ZonedDateTime which is in a DST overlap will have no effect. This isn't sensible, and could result in infinite loops where a developer calls plusHours(1) to advance time.

(this is hard to fix without changing to Joda-Time semantics above)

Member

sjmisterm commented Nov 29, 2012

The current Joda-Time strategy seems to be the right one.

Contributor

RogerRiggs commented Nov 29, 2012

ok; plus/minus time should to work as a duration; plus/minus on dates should resolve the time as needed.

jodastephen added a commit that referenced this issue Dec 3, 2012

Owner

jodastephen commented Dec 3, 2012

The period between/until calculation still needs work, but this the plus/period part is done.

Owner

jodastephen commented Dec 19, 2012

periodUntil implemented with reasonable tests (can never have enough tests...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment