Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Rust: compare datetime with fixedoffset to datetime with timezone

How does one convert between DateTime<FixedOffset> and DateTime<Tz>, in order to subtract to get a duration, compare inequality, or reassign?

An attempt to do this directly yields the error:

mismatched types
expected struct `DateTime<FixedOffset>`
   found struct `DateTime<Tz>`rustcE0308

Obligatory MRE:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    let mut a = DateTime::parse_from_rfc3339("2022-06-01T10:00:00").unwrap();
    let b = a.with_timezone(&New_York);
    a = b

>Solution :

Convert the timezone of b into the timezone of a before assigning it:

a = b.with_timezone(&a.timezone());
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading