chronotope / chrono

Date and time library for Rust
Other
3.3k stars 523 forks source link

Deprecate all timestamp-related methods on `NaiveDateTime` #1471

Closed pitdicker closed 7 months ago

pitdicker commented 7 months ago

The definition of a timestamp is that it is a value in UTC. We don't know how a NaiveDateTime relates to UTC. So having methods on this type to convert to and from timestamps is in theory not correct.

The time crate chooses to not have any timestamp related methods on its PrimitiveDateTime for this reason.

Workarounds are not that problematic. If the NaiveDate is in UTC dt.timestamp() would become dt.and_utc().timestamp(). NaiveDate::from_timestamp(ts, 0) would become Utc.timestamp(ts, 0).naive_utc().

Deprecating these methods can help users notice invalid assumptions, and removes 13 methods from our API surface.

djc commented 7 months ago

This makes sense to me.