chronotope / chrono

Date and time library for Rust
Other
3.35k stars 536 forks source link

Question about leap seconds in the context of message pack encoding #1609

Closed junderw closed 3 months ago

junderw commented 3 months ago

Context (which itself links to a PR trying to encode and decode chrono::DateTime with message pack): https://github.com/msgpack/msgpack/issues/339

Message Pack only encodes Unix timestamp, so in the case where nanoseconds is 1 billion or over, is it correct that I should modulo 1 billion and add 1 second to the seconds value?

djc commented 3 months ago

Yes, that sounds right. Are you not using any of chrono's serde implementations?

junderw commented 3 months ago

Unfortunately, the library is a bit lower level than serde.

(There exists a serde library on top of the encoding and decoding (using Read and Write extension traits))

The encoding of timestamps is pretty straightforward though, the only oddity was the protocol specifically states that nanoseconds must not be 1 billion or over.

Outside of this behavior, it's basically just a binary encoding of the seconds and nanoseconds value and not that difficult to reason about.

Thanks for the answer!