-
How do i convert a chrono DateTime to an OffsetDateTime, so i can use it to set the expire attribute on a cookie? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi, thanks for using trillium! It's been a bit since I've used the let offset_datetime = time::OffsetDateTime::from_unix_timestamp(chrono_datetime.timestamp()).unwrap(); For other use cases you might want to use sub second precision, but there really isn't any reason to be that precise for cookie expiry. We also don't need to retain the timezone offset because expiry doesn't happen in any particular timezone. Trillium currently exposes types from the |
Beta Was this translation helpful? Give feedback.
Hi, thanks for using trillium!
It's been a bit since I've used the
chrono
crate but looking at the docs suggests you should be able to convert between them by way of a unix timestamp:For other use cases you might want to use sub second precision, but there really isn't any reason to be that precise for cookie expiry. We also don't need to retain the timezone offset because expiry doesn't happen in any particular timezone.
Trillium currently exposes types from the
cookie
crate, so their choice of time library is also exposed.