Parse either fixed offset or Area/Location timezone

85 Views Asked by At

Here's my src/main.rs file:

use chrono_tz::Tz;

fn parse_ts(ts: &str) -> Tz {
    ts.parse().unwrap()
}

fn main() {
    let ts: &str = "UTC";
    println!("parsed: {:?}", parse_ts(ts));
}

It runs fine! But if I replace "UTC" with "+00:00", then it errors:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "'+00:00' is not a valid timezone"', src/main.rs:4:16

Can I rewrite it such that parse_ts can handle both fixed offsets and 'Area/Location' timezones?

0

There are 0 best solutions below