expression

Chrono-TZ ambiguous local time

During a backward clock transition one local reading may identify two instants. Present both choices or apply an explicit business rule; never assume the earlier one is always appropriate. This example uses external crates; see the staged Cargo manifest. Expected stdout (not executed): 2024-10-27T02:30:00+02:00 2024-10-27T02:30:00+01:00 Common mistake: Silently selecting an instant when the user has not specified which occurrence they mean.

Formal Syntax & Structure

rust syntaxrust
LocalResult::Ambiguous(earlier, later)

Working Example

Example Snippetrust
fn main() {    use chrono::{LocalResult, NaiveDate, TimeZone};    use chrono_tz::Europe::Paris;    let wall = NaiveDate::from_ymd_opt(2024, 10, 27).unwrap().and_hms_opt(2, 30, 0).unwrap();    match Paris.from_local_datetime(&wall) {        LocalResult::Ambiguous(a, b) => println!("{}\n{}", a.to_rfc3339(), b.to_rfc3339()),        _ => println!("unexpected mapping"),    }}
Rust Reference