mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Merge pull request #5030 from cakebaker/touch_use_parse_datetime
touch: use parse_datetime instead of humantime_to_duration
This commit is contained in:
commit
37cbfd1efd
4 changed files with 13 additions and 24 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -1172,16 +1172,6 @@ dependencies = [
|
||||||
"winapi",
|
"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]]
|
[[package]]
|
||||||
name = "iana-time-zone"
|
name = "iana-time-zone"
|
||||||
version = "0.1.53"
|
version = "0.1.53"
|
||||||
|
@ -3237,7 +3227,7 @@ version = "0.0.19"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"filetime",
|
"filetime",
|
||||||
"humantime_to_duration",
|
"parse_datetime",
|
||||||
"time",
|
"time",
|
||||||
"uucore",
|
"uucore",
|
||||||
"windows-sys 0.48.0",
|
"windows-sys 0.48.0",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# coreutils (uutils)
|
# coreutils (uutils)
|
||||||
# * see the repository LICENSE, README, and CONTRIBUTING files for more information
|
# * 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]
|
[package]
|
||||||
name = "coreutils"
|
name = "coreutils"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# spell-checker:ignore humantime
|
# spell-checker:ignore datetime
|
||||||
[package]
|
[package]
|
||||||
name = "uu_touch"
|
name = "uu_touch"
|
||||||
version = "0.0.19"
|
version = "0.0.19"
|
||||||
|
@ -18,8 +18,7 @@ path = "src/touch.rs"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
filetime = { workspace = true }
|
filetime = { workspace = true }
|
||||||
clap = { workspace = true }
|
clap = { workspace = true }
|
||||||
# TODO: use workspace dependency (0.3) when switching from time to chrono
|
parse_datetime = { workspace = true }
|
||||||
humantime_to_duration = "0.2.1"
|
|
||||||
time = { workspace = true, features = [
|
time = { workspace = true, features = [
|
||||||
"parsing",
|
"parsing",
|
||||||
"formatting",
|
"formatting",
|
||||||
|
|
|
@ -84,13 +84,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
) {
|
) {
|
||||||
(Some(reference), Some(date)) => {
|
(Some(reference), Some(date)) => {
|
||||||
let (atime, mtime) = stat(Path::new(reference), !matches.get_flag(options::NO_DEREF))?;
|
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 seconds = offset.num_seconds();
|
||||||
let mut nanos = offset.subsec_nanoseconds();
|
let nanos = offset.num_nanoseconds().unwrap_or(0) % 1_000_000_000;
|
||||||
if nanos < 0 {
|
|
||||||
nanos += 1_000_000_000;
|
|
||||||
seconds -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
let ref_atime_secs = atime.unix_seconds();
|
let ref_atime_secs = atime.unix_seconds();
|
||||||
let ref_atime_nanos = atime.nanoseconds();
|
let ref_atime_nanos = atime.nanoseconds();
|
||||||
|
@ -445,9 +441,13 @@ fn parse_date(s: &str) -> UResult<FileTime> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 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));
|
return Ok(local_dt_to_filetime(diff));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue