Skip to content

Commit

Permalink
Make iana-time-zone weaker dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
dshmatkou committed Apr 17, 2023
1 parent 43579a5 commit e93c499
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Expand Up @@ -16,11 +16,11 @@ edition = "2018"
name = "chrono"

[features]
default = ["clock", "std", "wasmbind"]
default = ["clock", "std", "wasmbind", "iana-time-zone"]
alloc = []
libc = []
std = []
clock = ["std", "windows-sys", "iana-time-zone"]
clock = ["std", "windows-sys"]
wasmbind = ["wasm-bindgen", "js-sys"]
unstable-locales = ["pure-rust-locales", "alloc"]
__internal_bench = ["criterion"]
Expand Down
6 changes: 6 additions & 0 deletions src/offset/local/unix.rs
Expand Up @@ -78,12 +78,18 @@ const TZDB_LOCATION: &str = "/usr/share/lib/zoneinfo";
#[cfg(not(any(target_os = "android", target_os = "aix")))]
const TZDB_LOCATION: &str = "/usr/share/zoneinfo";

#[cfg(feature = "iana-time-zone")]
fn fallback_timezone() -> Option<TimeZone> {
let tz_name = iana_time_zone::get_timezone().ok()?;
let bytes = fs::read(format!("{}/{}", TZDB_LOCATION, tz_name)).ok()?;
TimeZone::from_tz_data(&bytes).ok()
}

#[cfg(not(feature = "iana-time-zone"))]
fn fallback_timezone() -> Option<TimeZone> {
None
}

impl Default for Cache {
fn default() -> Cache {
// default to UTC if no local timezone can be found
Expand Down

0 comments on commit e93c499

Please sign in to comment.