Skip to content
Discussion options

You must be logged in to vote

You should be able to do this (I haven't checked it):

let mut odt: OffsetDateTime = system_time.into();
let offset = UtcOffset::local_offset_at(odt)?;
odt = odt.to_offset(offset);

Keep in mind that the second line will fail if any of the following is true:

  • the offset cannot be determined
  • the program is multithreaded (this doesn't apply to Windows)
  • the num_threads crate does not support the operating system, resulting in whether the program is multithreaded unknowable

I had never considered adding an OffsetDateTime::to_local_offset(self) -> Result<Self, error:IndeterminateOffset> method, but I could certainly see the utility. I will look into whether this makes sense and would be suffici…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@SpriteOvO
Comment options

@jhpratt
Comment options

@SpriteOvO
Comment options

Answer selected by SpriteOvO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #420 on January 05, 2022 20:59.