OXYGENHUB
◆ v0.8.0 oxygen / vendor / iana-time-zone / src / tz_netbsd.rs
879 B · Rust · last changed Strata: the cloud stores send through ureq, so every release target links 1 month ago source blame history raw
1
use std::fs::read_link;
2
3
pub(crate) fn get_timezone_inner() -> Result<String, crate::GetTimezoneError> {
4
    // see https://www.cyberciti.biz/faq/openbsd-time-zone-howto/
5
6
    // This is a backport of the Linux implementation.
7
    // NetBSDs is less than thorough how the softlink should be set up.
8
9
    const PREFIXES: &[&str] = &[
10
        "/usr/share/zoneinfo/",   // absolute path
11
        "../usr/share/zoneinfo/", // relative path
12
    ];
13
    let mut s = read_link("/etc/localtime")?
14
        .into_os_string()
15
        .into_string()
16
        .map_err(|_| crate::GetTimezoneError::FailedParsingString)?;
17
    for &prefix in PREFIXES {
18
        if s.starts_with(prefix) {
19
            // Trim to the correct length without allocating.
20
            s.replace_range(..prefix.len(), "");
21
            return Ok(s);
22
        }
23
    }
24
    Err(crate::GetTimezoneError::FailedParsingString)
25
}