97jaz / gregor

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

bug: `now` datetime doesn't round-trip with its ISO 8601 representation #3

Closed 97jaz closed 9 years ago

97jaz commented 9 years ago
#lang racket/base

(require gregor)

(define a (now))
(define b (iso8601->datetime (datetime->iso8601 a)))
(datetime=? a b)
(->jd a)
(->jd b)

... yields ...

#f
2457125 4151950453/11796480000
2457125 15204896678467/43200000000000
97jaz commented 9 years ago

More info: the problem is specifically with JD generation. The resulting datetime actually has the correct date and time. It just doesn't have the correct JD (which is what the comparison functions use).

date+time->datetime uses one algorithm to generate the JD from the date and time, whereas posix->datetime generates a JD first, from the posix seconds, and then finds the date and time from that. The clock functions generate datetimes from the posix value, whereas the ISO 8601 parsing functions use date+time->datetime.

It's simple enough to ensure that only one algorithm is used to generate the JD, but I should first figure out why they generate different results.

97jaz commented 9 years ago

Fixed by #6.