iana-time-zone 0.1.19

get the IANA time zone for the current system
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
pub(crate) fn get_timezone_inner() -> Result<String, crate::GetTimezoneError> {
    let tz = core_foundation::timezone::CFTimeZone::system();

    // Get string like ""Europe/Berlin (GMT+2) offset 7200 (Daylight)""
    let mut str1 = format!("{:?}", tz);

    // strip leading double quotes
    while str1.starts_with('"') {
        str1 = str1[1..].to_string();
    }

    match str1.split_whitespace().next() {
        Some(s) => Ok(s.to_string()),
        None => Err(crate::GetTimezoneError::FailedParsingString),
    }
}