diff --git a/Cargo.lock b/Cargo.lock index cce3816cfe0..61d8fcf05e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1154,6 +1154,16 @@ dependencies = [ "time", ] +[[package]] +name = "humantime_to_duration" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a80a233096ddccb74e62145f3a49cacea6a2669ee90f6e144e15fe28f4037c4" +dependencies = [ + "chrono", + "regex", +] + [[package]] name = "iana-time-zone" version = "0.1.53" @@ -2528,9 +2538,8 @@ version = "0.0.19" dependencies = [ "chrono", "clap", - "humantime_to_duration", + "humantime_to_duration 0.3.1", "libc", - "time", "uucore", "windows-sys 0.48.0", ] @@ -3224,7 +3233,7 @@ version = "0.0.19" dependencies = [ "clap", "filetime", - "humantime_to_duration", + "humantime_to_duration 0.2.1", "time", "uucore", "windows-sys 0.48.0", diff --git a/Cargo.toml b/Cargo.toml index c67aaa9a900..1e6e220889d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -286,7 +286,7 @@ fundu = "0.5.1" gcd = "2.3" glob = "0.3.1" half = "2.2" -humantime_to_duration = "0.2.1" +humantime_to_duration = "0.3.1" indicatif = "0.17" is-terminal = "0.4.7" itertools = "0.10.5" diff --git a/deny.toml b/deny.toml index 14470b9b0db..c8498423048 100644 --- a/deny.toml +++ b/deny.toml @@ -78,6 +78,8 @@ skip = [ { name = "redox_syscall", version = "0.3.5" }, # cpp_macros { name = "aho-corasick", version = "0.7.19" }, + # touch, can be remove when touch switches from time to chrono + { name = "humantime_to_duration", version = "0.2.1" }, ] # spell-checker: enable diff --git a/src/uu/date/Cargo.toml b/src/uu/date/Cargo.toml index 852e8cc9d12..1ffcbed6665 100644 --- a/src/uu/date/Cargo.toml +++ b/src/uu/date/Cargo.toml @@ -17,8 +17,6 @@ path = "src/date.rs" [dependencies] chrono = { workspace=true } -#/ TODO: check if we can avoid chrono+time -time = { workspace=true } clap = { workspace=true } uucore = { workspace=true } humantime_to_duration = { workspace=true } diff --git a/src/uu/date/src/date.rs b/src/uu/date/src/date.rs index 381619f06fb..44b54be5e8b 100644 --- a/src/uu/date/src/date.rs +++ b/src/uu/date/src/date.rs @@ -9,7 +9,7 @@ // spell-checker:ignore (chrono) Datelike Timelike ; (format) DATEFILE MMDDhhmm ; (vars) datetime datetimes humantime use chrono::format::{Item, StrftimeItems}; -use chrono::{DateTime, Duration as ChronoDuration, FixedOffset, Local, Offset, Utc}; +use chrono::{DateTime, Duration, FixedOffset, Local, Offset, Utc}; #[cfg(windows)] use chrono::{Datelike, Timelike}; use clap::{crate_version, Arg, ArgAction, Command}; @@ -18,7 +18,6 @@ use libc::{clock_settime, timespec, CLOCK_REALTIME}; use std::fs::File; use std::io::{BufRead, BufReader}; use std::path::PathBuf; -use time::Duration; use uucore::display::Quotable; #[cfg(not(any(target_os = "redox")))] use uucore::error::FromIo; @@ -226,13 +225,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let iter = std::iter::once(date); Box::new(iter) } - DateSource::Human(ref input) => { - // Get the current DateTime and convert the input time::Duration to chrono::Duration - // for things like "1 year ago" + DateSource::Human(relative_time) => { + // Get the current DateTime for things like "1 year ago" let current_time = DateTime::::from(Local::now()); - let input_chrono = ChronoDuration::seconds(input.as_seconds_f32() as i64) - + ChronoDuration::nanoseconds(input.subsec_nanoseconds() as i64); - let iter = std::iter::once(Ok(current_time + input_chrono)); + let iter = std::iter::once(Ok(current_time + relative_time)); Box::new(iter) } DateSource::File(ref path) => { diff --git a/src/uu/touch/Cargo.toml b/src/uu/touch/Cargo.toml index 3aac9abc474..80840525c01 100644 --- a/src/uu/touch/Cargo.toml +++ b/src/uu/touch/Cargo.toml @@ -18,7 +18,8 @@ path = "src/touch.rs" [dependencies] filetime = { workspace=true } clap = { workspace=true } -humantime_to_duration = { workspace=true } +# TODO: use workspace dependency (0.3) when switching from time to chrono +humantime_to_duration = "0.2.1" time = { workspace=true, features = ["parsing", "formatting", "local-offset", "macros"] } uucore = { workspace=true, features=["libc"] }