time-rs / time

The most used Rust library for date and time handling.
https://time-rs.github.io
Apache License 2.0
1.09k stars 273 forks source link

OffsetDateTime -> PrimitiveDateTime #553

Closed lpotthast closed 1 year ago

lpotthast commented 1 year ago

We can use assume_utc and others to convert a PrimitiveDateTime to an OffsetDateTime. But there does not seem to be an easy way of converting back to a PrimitiveDateTime, that means: simply dropping the offset information.

Use case: Use PrimitiveDateTime for something like a database field, at which no offset information is required (UTC always implied). We still want to use "now" functions. As there is only OffsetDateTime::now_utc() and no PrimitiveDateTime::now_***(), a conversion only seems possible with

{
    let now = time::OffsetDateTime::now_utc();
    time::PrimitiveDateTime::new(now.date(), now.time())
}

I think there should either be a From/Into implementation or an appropriately named function for some or both types, which lets you do this using a single function call.

jhpratt commented 1 year ago

Duplicate of #369, #390, #395, #454, and #458.