Skip to content

Commit

Permalink
Merge bc22dd2 into e4c5607
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkna committed Aug 17, 2022
2 parents e4c5607 + bc22dd2 commit f7d6eb0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ all-features = true
is_debug = "1.0.1"
const_format = "0.2.22"
time = { version = "0.3.11", features = ["formatting", "local-offset", "parsing"] }
tzdb = { version = "0.4.3", default-features = false, features = ["local", "std"] }

#! Optional Dependencies:

## Use `libgit2` as a backend for git operations
git2 = { version = "0.15.0", default-features = false, optional = true }

## Better support for querying the local system time
tzdb = { version = "0.4.3", optional = true, default-features = false, features = ["local", "std"] }

document-features = { version = "0.2", optional = true }

[features]
default = ["git2"]
default = ["git2", "tzdb"]

[workspace]
members = ["example_shadow", "example_shadow_hook"]
8 changes: 8 additions & 0 deletions src/data_time.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::Format;
use std::error::Error;
#[cfg(feature = "tzdb")]
use std::time::{SystemTime, UNIX_EPOCH};
use time::format_description::well_known::{Rfc2822, Rfc3339};
#[cfg(feature = "tzdb")]
use time::UtcOffset;
use time::{format_description, OffsetDateTime};

Expand Down Expand Up @@ -48,6 +50,12 @@ impl DateTime {
}
}

#[cfg(not(feature = "tzdb"))]
pub fn local_now() -> Result<Self, Box<dyn Error>> {
OffsetDateTime::now_local().map(DateTime::Local).map_err(|e| e.into())
}

#[cfg(feature = "tzdb")]
pub fn local_now() -> Result<Self, Box<dyn Error>> {
// expensive call, should be cached
let time_zone_local = tzdb::local_tz().ok_or("Could not get local timezone")?;
Expand Down

0 comments on commit f7d6eb0

Please sign in to comment.