Sha256: ec278bbe1cb5f648c063ec23bff6081146454b9f6aa3918b9ca50b8804d5838f

Contents?: true

Size: 879 Bytes

Versions: 19

Compression:

Stored size: 879 Bytes

Contents

use std::fs::read_link;

pub(crate) fn get_timezone_inner() -> Result<String, crate::GetTimezoneError> {
    // see https://www.cyberciti.biz/faq/openbsd-time-zone-howto/

    // This is a backport of the Linux implementation.
    // NetBSDs is less than thorough how the softlink should be set up.

    const PREFIXES: &[&str] = &[
        "/usr/share/zoneinfo/",   // absolute path
        "../usr/share/zoneinfo/", // relative path
    ];
    let mut s = read_link("/etc/localtime")?
        .into_os_string()
        .into_string()
        .map_err(|_| crate::GetTimezoneError::FailedParsingString)?;
    for &prefix in PREFIXES {
        if s.starts_with(prefix) {
            // Trim to the correct length without allocating.
            s.replace_range(..prefix.len(), "");
            return Ok(s);
        }
    }
    Err(crate::GetTimezoneError::FailedParsingString)
}

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/iana-time-zone-0.1.61/src/tz_netbsd.rs
wasmtime-28.0.0 ./ext/cargo-vendor/iana-time-zone-0.1.61/src/tz_netbsd.rs
wasmtime-27.0.0 ./ext/cargo-vendor/iana-time-zone-0.1.61/src/tz_netbsd.rs
wasmtime-26.0.0 ./ext/cargo-vendor/iana-time-zone-0.1.61/src/tz_netbsd.rs
wasmtime-25.0.2 ./ext/cargo-vendor/iana-time-zone-0.1.60/src/tz_netbsd.rs
wasmtime-25.0.1 ./ext/cargo-vendor/iana-time-zone-0.1.60/src/tz_netbsd.rs
wasmtime-25.0.0 ./ext/cargo-vendor/iana-time-zone-0.1.60/src/tz_netbsd.rs
wasmtime-24.0.0 ./ext/cargo-vendor/iana-time-zone-0.1.60/src/tz_netbsd.rs
wasmtime-23.0.2 ./ext/cargo-vendor/iana-time-zone-0.1.59/src/tz_netbsd.rs
wasmtime-22.0.0 ./ext/cargo-vendor/iana-time-zone-0.1.59/src/tz_netbsd.rs
wasmtime-21.0.1 ./ext/cargo-vendor/iana-time-zone-0.1.59/src/tz_netbsd.rs
wasmtime-20.0.2 ./ext/cargo-vendor/iana-time-zone-0.1.59/src/tz_netbsd.rs
wasmtime-20.0.0 ./ext/cargo-vendor/iana-time-zone-0.1.59/src/tz_netbsd.rs
wasmtime-18.0.3 ./ext/cargo-vendor/iana-time-zone-0.1.59/src/tz_netbsd.rs
wasmtime-17.0.1 ./ext/cargo-vendor/iana-time-zone-0.1.59/src/tz_netbsd.rs
wasmtime-17.0.0 ./ext/cargo-vendor/iana-time-zone-0.1.59/src/tz_netbsd.rs
wasmtime-16.0.0 ./ext/cargo-vendor/iana-time-zone-0.1.59/src/tz_netbsd.rs
wasmtime-15.0.1 ./ext/cargo-vendor/iana-time-zone-0.1.59/src/tz_netbsd.rs
wasmtime-15.0.0 ./ext/cargo-vendor/iana-time-zone-0.1.59/src/tz_netbsd.rs