Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to tzdb 0.5.0 #120

Merged
merged 2 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ time = { version = "0.3.11", features = ["formatting", "local-offset", "parsing"
git2 = { version = "0.15.0", default-features = false, optional = true }

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

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

Expand Down
16 changes: 5 additions & 11 deletions src/data_time.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
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;
Expand Down Expand Up @@ -62,15 +60,11 @@ impl DateTime {

#[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")?;

let duration_since_epoch = SystemTime::now().duration_since(UNIX_EPOCH)?;
let local_time_type =
time_zone_local.find_local_time_type(duration_since_epoch.as_secs().try_into()?)?;
let time_zone_offset = UtcOffset::from_whole_seconds(local_time_type.ut_offset())?;
let local_date_time =
(OffsetDateTime::UNIX_EPOCH + duration_since_epoch).to_offset(time_zone_offset);
let local_time = tzdb::now::local()?;
let time_zone_offset =
UtcOffset::from_whole_seconds(local_time.local_time_type().ut_offset())?;
let local_date_time = OffsetDateTime::from_unix_timestamp(local_time.unix_time())?
.to_offset(time_zone_offset);
Ok(DateTime::Local(local_date_time))
}

Expand Down
2 changes: 1 addition & 1 deletion src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl SystemEnv {
}

if let Ok(_out) = Command::new("cargo")
.args(&["metadata", "--format-version", "1"])
.args(["metadata", "--format-version", "1"])
.output()
{
//TODO completed
Expand Down
6 changes: 3 additions & 3 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ pub fn git_status_file() -> String {
/// Command exec git current tag
fn command_current_tag() -> Option<String> {
Command::new("git")
.args(&["tag", "-l", "--contains", "HEAD"])
.args(["tag", "-l", "--contains", "HEAD"])
.output()
.map(|x| String::from_utf8(x.stdout).ok())
.map(|x| x.map(|x| x.trim().to_string()))
Expand All @@ -359,7 +359,7 @@ fn command_current_tag() -> Option<String> {
/// check repository git status is clean
fn command_git_clean() -> bool {
Command::new("git")
.args(&["status", "--porcelain"])
.args(["status", "--porcelain"])
.output()
.map(|x| String::from_utf8(x.stdout).ok())
.map(|x| x.map(|x| x.trim().to_string()))
Expand Down Expand Up @@ -418,7 +418,7 @@ fn command_git_status_file() -> String {
/// Command exec git current branch
fn command_current_branch() -> Option<String> {
Command::new("git")
.args(&["symbolic-ref", "--short", "HEAD"])
.args(["symbolic-ref", "--short", "HEAD"])
.output()
.map(|x| String::from_utf8(x.stdout).ok())
.map(|x| x.map(|x| x.trim().to_string()))
Expand Down