Date->seconds and time-zone-offsets

I hope someone can clarify this.

I'm experimenting with racket dates and timezone info. I did following:

Welcome to DrRacket, version 8.18 [cs].
Language: racket/base [custom].
> (define s (current-seconds))
> (define d1 (seconds->date s))
> (define d-utc (seconds->date s #f))
> d1
(date* 29 22 13 26 8 2025 2 237 #f 7200 0 "West-Europa (zomertijd)")
> d-utc
(date* 29 22 11 26 8 2025 2 237 #f 0 0 "UTC")
> (define s1 (date->seconds d-utc))
> (define s2 (date->seconds d1))
> s1
1756200149
> s2
1756207349
> s
1756207349
> 

Now, as one can see, 's' is (current-seconds).

When I convert with seconds->date , it looks like the right date* structs are created.

Now, I convert back from d1 (which is in localtime) and d-utc.

I would expect s1 and s2 to be equal (i.e. (= s1 s2) gives #t). And both would be equal to s.

But this is not the case.

Consulting https://www.epochconverter.com/

Local time (CET) to seconds:

GMT time (UTC) to seconds:

Am I missing something in racket?

1 Like

What you are missing is:

The date and date* structs from the racket libraries, which are relics of our Scheme heritage, deal at best with UTC offsets with names, which are a crude approximation of the complex things we call “time zones.” In fairness, I think there probably is some way of getting them to do what you want in your example, but, for any non-trivial use of dates or times in Racket, you are best off leaving them behind and embracing the replacements from Gregor. Even the documentation for racket/date recommends Gregor!

Ah, oké! Thanks you, I’ll use gregor dates. Does this also do conversions from seconds/strings to dates/times + timezone conversions?

Just 1 other question about this. Are there conversions functions from racket dates to gregor dates/datetimes/moments and vise versa?

Maybe it is of no concern…

Why is the gregor module not part of the racket standard set btw?

Potentially stepping on mines here, but... I think that gregor offers an entirely parallel time library; I believe there are no conversion functions because if you're going to use Gregor, you're probably "all in," and you would likely never touch racket dates at all. In fact, my recollection is that there are name collisions, so it's at least mildly difficult to use both of them.

I like gregor, and I tend to use it. With that said, I usually spend more time than I would like searching for a particular conversion function. I would say that Gregor suffers from three problems, and none is a deal-killer. First, it uses a naming convention that is somewhat idiosyncratic. Second, it could use some "streamlining", the kind of thing that happens when a library (both documentation and functionality) adapts to widespread usage. Third, time itself is kind of a nightmare (a "time" is different from a "date", there are multiple distinct ideas and english terms are often used in different ways), and Gregor is both confident and firm in its distinctions.

These are all just my opinions.

Third, time itself is kind of a nightmare

Indeed. Reading this article and its follow-up was enlightening: Falsehoods programmers believe about time: @noahsussman: Infinite Undo