From 9aef5ac35b974e1f081fd4d5d0e29a4e41fd58c5 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sun, 11 Jun 2023 10:35:32 -0500 Subject: [PATCH 1/3] deps ~ change from 'humantime_to_duration' to 'parse_datetime' --- Cargo.toml | 2 +- src/uu/touch/Cargo.toml | 5 ++--- src/uu/touch/src/touch.rs | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ed9971d9584..2828c00dfd1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ # coreutils (uutils) # * see the repository LICENSE, README, and CONTRIBUTING files for more information -# spell-checker:ignore (libs) libselinux gethostid procfs bigdecimal kqueue fundu mangen datetime uuhelp memmap +# spell-checker:ignore (libs) bigdecimal datetime fundu gethostid kqueue libselinux mangen memmap procfs uuhelp [package] name = "coreutils" diff --git a/src/uu/touch/Cargo.toml b/src/uu/touch/Cargo.toml index f90725197b8..4e27027a2eb 100644 --- a/src/uu/touch/Cargo.toml +++ b/src/uu/touch/Cargo.toml @@ -1,4 +1,4 @@ -# spell-checker:ignore humantime +# spell-checker:ignore datetime [package] name = "uu_touch" version = "0.0.19" @@ -18,8 +18,7 @@ path = "src/touch.rs" [dependencies] filetime = { workspace = true } clap = { workspace = true } -# TODO: use workspace dependency (0.3) when switching from time to chrono -humantime_to_duration = "0.2.1" +parse_datetime = { workspace = true } time = { workspace = true, features = [ "parsing", "formatting", diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index 4efea56c4c6..d3d4a08c56f 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -84,7 +84,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { ) { (Some(reference), Some(date)) => { let (atime, mtime) = stat(Path::new(reference), !matches.get_flag(options::NO_DEREF))?; - if let Ok(offset) = humantime_to_duration::from_str(date) { + if let Ok(offset) = parse_datetime::from_str(date) { let mut seconds = offset.whole_seconds(); let mut nanos = offset.subsec_nanoseconds(); if nanos < 0 { @@ -445,7 +445,7 @@ fn parse_date(s: &str) -> UResult { } } - if let Ok(duration) = humantime_to_duration::from_str(s) { + if let Ok(duration) = parse_datetime::from_str(s) { let now_local = time::OffsetDateTime::now_local().unwrap(); let diff = now_local.checked_add(duration).unwrap(); return Ok(local_dt_to_filetime(diff)); From af64bde92b5f29cc1cb6519e29aae821b6afcf23 Mon Sep 17 00:00:00 2001 From: Roy Ivy III Date: Sun, 11 Jun 2023 19:45:06 -0500 Subject: [PATCH 2/3] fix/touch ~ time crate usage errors --- src/uu/touch/src/touch.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index d3d4a08c56f..f4784f155a7 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -85,12 +85,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { (Some(reference), Some(date)) => { let (atime, mtime) = stat(Path::new(reference), !matches.get_flag(options::NO_DEREF))?; if let Ok(offset) = parse_datetime::from_str(date) { - let mut seconds = offset.whole_seconds(); - let mut nanos = offset.subsec_nanoseconds(); - if nanos < 0 { - nanos += 1_000_000_000; - seconds -= 1; - } + let seconds = offset.num_seconds(); + let nanos = offset.num_nanoseconds().unwrap_or(0) % 1_000_000_000; let ref_atime_secs = atime.unix_seconds(); let ref_atime_nanos = atime.nanoseconds(); @@ -447,7 +443,11 @@ fn parse_date(s: &str) -> UResult { if let Ok(duration) = parse_datetime::from_str(s) { let now_local = time::OffsetDateTime::now_local().unwrap(); - let diff = now_local.checked_add(duration).unwrap(); + let diff = now_local + .checked_add(time::Duration::nanoseconds( + duration.num_nanoseconds().unwrap(), + )) + .unwrap(); return Ok(local_dt_to_filetime(diff)); } From e6ec1490aac2c7df5eed59791126e61c97070549 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Mon, 3 Jul 2023 14:28:39 +0200 Subject: [PATCH 3/3] touch: use parse_datetime in Cargo.lock --- Cargo.lock | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fa23c1ace69..77afc44708b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1172,16 +1172,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "humantime_to_duration" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "714764645f21cc70c4c151d7798dd158409641f37ad820bed65224aae403cbed" -dependencies = [ - "regex", - "time", -] - [[package]] name = "iana-time-zone" version = "0.1.53" @@ -3237,7 +3227,7 @@ version = "0.0.19" dependencies = [ "clap", "filetime", - "humantime_to_duration", + "parse_datetime", "time", "uucore", "windows-sys 0.48.0",