this post was submitted on 22 Jul 2024
78 points (97.6% liked)
Rust
5744 readers
7 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
Credits
- The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I think you misunderstood me.
What I meant is, someone who wants to serialize zoned dt info using chrono can basically send a timestamp and a timezone name on the wire, e.g.
(1721599162, "America/New_York")
.It's not built-in support. It's not a single human-readable string containing all the needed info that is being sent on the wire. But it does provide the needed info to get the correct results on the other side. And it's the obvious solution to do, and it's doable with trivial wrappers. No
Local
+FixedOffset
usage required. And no wrong results inevitable.Right. That's exactly what the code snippet says:
So I feel like the point you're making here is already covered by the example comparison I wrote. It's not built-in, so you have to invent your own interchange format. And since your serialized format doesn't include offset information at the time the instant was created, it's impossible to do offset conflict resolution. For example, let's say you record one year from today in Ukraine:
And the output:
And maybe you store this datetime somewhere.
At this point, it's looking like Ukraine is going to abolish DST for next year. So what happens to that datetime above? It no longer has the right offset. So now you need to choose whether to reject it altogether (the default), respect the offset (even if the civil time changes) or respect the civil time (even if the instant changes).
Here's an example of when this happened with Brazil abolishing DST: https://docs.rs/jiff/latest/jiff/fmt/temporal/struct.DateTimeParser.html#example-3
Why is the full presentation non-ephemerally stored instead of
(timestamp, timezoe)
?Is the use-case strictly limited to checking the validity of a future date that was generated with assumptions based on current tzdata info? That's valid, but quite niche I would argue.
And one can adjust the wrapper to have
(timestamp, timezone, assumed_offset_at_ts)
. But yes, it can be argued that it's not idiomatic/automatic/antecedently obvious anymore.And the fact that you need to create a wrapper means that some programmers won't bother to do it, or won't know they need to do it. The default case handling timezones correctly will reduce potential errors.