diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5c8d8d53fa..a18e07aaf0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -100,7 +100,14 @@ jobs: strategy: matrix: os: [ubuntu-latest] - target: [wasm32-unknown-unknown, wasm32-wasi, wasm32-unknown-emscripten, aarch64-apple-ios, aarch64-linux-android] + target: + [ + wasm32-unknown-unknown, + wasm32-wasi, + wasm32-unknown-emscripten, + aarch64-apple-ios, + aarch64-linux-android, + ] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 diff --git a/Cargo.toml b/Cargo.toml index 23ffda6ea2..b925dc1431 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,6 +49,9 @@ winapi = { version = "0.3.0", features = ["std", "minwinbase", "minwindef", "tim [target.'cfg(unix)'.dependencies] iana-time-zone = { version = "0.1.45", optional = true, features = ["fallback"] } +[target.'cfg(target_os = "android")'.dependencies] +android-tzdata = "0.1.1" + [dev-dependencies] serde_json = { version = "1" } serde_derive = { version = "1", default-features = false } diff --git a/src/offset/local/tz_info/timezone.rs b/src/offset/local/tz_info/timezone.rs index 2fe24d2e44..33c89060ce 100644 --- a/src/offset/local/tz_info/timezone.rs +++ b/src/offset/local/tz_info/timezone.rs @@ -43,6 +43,14 @@ impl TimeZone { return Self::from_tz_data(&fs::read("/etc/localtime")?); } + // attributes are not allowed on if blocks in Rust 1.38 + #[cfg(target_os = "android")] + { + if let Ok(bytes) = android_tzdata::find_tz_data(tz_string) { + return Self::from_tz_data(&bytes); + } + } + let mut chars = tz_string.chars(); if chars.next() == Some(':') { return Self::from_file(&mut find_tz_file(chars.as_str())?); diff --git a/src/offset/local/unix.rs b/src/offset/local/unix.rs index 22114f21ef..68b206cd90 100644 --- a/src/offset/local/unix.rs +++ b/src/offset/local/unix.rs @@ -68,19 +68,18 @@ struct Cache { last_checked: SystemTime, } -#[cfg(target_os = "android")] -const TZDB_LOCATION: &str = " /system/usr/share/zoneinfo"; - #[cfg(target_os = "aix")] const TZDB_LOCATION: &str = "/usr/share/lib/zoneinfo"; -#[allow(dead_code)] // keeps the cfg simpler #[cfg(not(any(target_os = "android", target_os = "aix")))] const TZDB_LOCATION: &str = "/usr/share/zoneinfo"; fn fallback_timezone() -> Option { let tz_name = iana_time_zone::get_timezone().ok()?; + #[cfg(not(target_os = "android"))] let bytes = fs::read(format!("{}/{}", TZDB_LOCATION, tz_name)).ok()?; + #[cfg(target_os = "android")] + let bytes = android_tzdata::find_tz_data(&tz_name).ok()?; TimeZone::from_tz_data(&bytes).ok() }