97jaz / gregor

Date and time library for Racket
45 stars 10 forks source link

days-between on moments should not be timezone-sensitive #2

Closed 97jaz closed 9 years ago

97jaz commented 9 years ago

... following the convention that date arithmetic is not timezone-sensitive, whereas time arithmetic is.

Received the following in a bug report:

(define a (moment 2015 3 29 #:tz "Europe/Berlin"))
(define b (moment 2015 3 30 #:tz "Europe/Berlin"))

; surprised me a little:
(days-between a b)
; => 0

; not surprising:
(moment=? (+days a 1) b)
; => #t
(hours-between a b)
; => 23

Fix is straightforward, I think: days-between on datetime providers should use the JD of the local datetime values of its arguments, not the UTC datetime values.

moment->jd shouldn't be changed, though. This is peculiar to date arithmetic.

97jaz commented 9 years ago

Actually, no, this isn't so simple.

The purpose of using ->datetime/utc is to use the same offset for both arguments to days-between. You should be able to find the days between moments in different time zones, which means that days-between can't be entirely tz-insensitive... which may be a bit of a problem.

Or maybe we should translate the second argument into the TZ of the first, then use the local datetimes? I'll need to see how this interacts with duration-between. (Though if I need to choose between them, I'll drop the latter.)

97jaz commented 9 years ago

It appears that java.time does what I suggested in the previous comment, viz., translates the second arguments into the same TZ as the first and then uses the local datetimes.

97jaz commented 9 years ago

Fixed by https://github.com/97jaz/gregor/pull/5