From f764be8ddf0754bc5725844fc0d2718caba57a05 Mon Sep 17 00:00:00 2001 From: naoNao89 <90588855+naoNao89@users.noreply.github.com> Date: Wed, 15 Oct 2025 09:21:09 +0700 Subject: [PATCH] touch: fix parse_datetime 0.13 API usage for deterministic relative dates The previous implementation incorrectly used parse_datetime() instead of parse_datetime_at_date(), causing relative date strings like 'yesterday' or '2 days ago' to be calculated from the current system time instead of the caller-specified reference time. This fix: - Uses parse_datetime_at_date() with proper chrono->jiff->chrono conversions - Restores deterministic behavior for relative date parsing - Adds jiff 0.2.15 as direct dependency (not workspace) to avoid feature conflicts - Ensures tests/touch/relative passes in CI Note on jiff dependency: parse_datetime 0.13 depends on jiff ^0.2.15 with specific features. Adding jiff via workspace dependency causes feature unification conflicts across platforms. Using a direct dependency with version 0.2.15 resolves this while maintaining compatibility with parse_datetime's requirements. --- Cargo.lock | 7 ++++--- src/uu/touch/Cargo.toml | 1 + src/uu/touch/src/touch.rs | 36 +++++++++++++++++++++++++++++------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4e2996c83..833f11516 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -508,7 +508,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" dependencies = [ "lazy_static", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -1074,7 +1074,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cea14ef9355e3beab063703aa9dab15afd25f0667c341310c1e5274bb1d0da18" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -1667,7 +1667,7 @@ dependencies = [ "portable-atomic", "portable-atomic-util", "serde", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -4127,6 +4127,7 @@ dependencies = [ "clap", "filetime", "fluent", + "jiff", "parse_datetime", "thiserror 2.0.17", "uucore", diff --git a/src/uu/touch/Cargo.toml b/src/uu/touch/Cargo.toml index 55ac39bd8..f5409ec7a 100644 --- a/src/uu/touch/Cargo.toml +++ b/src/uu/touch/Cargo.toml @@ -22,6 +22,7 @@ path = "src/touch.rs" filetime = { workspace = true } clap = { workspace = true } chrono = { workspace = true } +jiff = "0.2.15" parse_datetime = { workspace = true } thiserror = { workspace = true } uucore = { workspace = true, features = ["libc", "parser"] } diff --git a/src/uu/touch/src/touch.rs b/src/uu/touch/src/touch.rs index 7f7464094..b1581f8f0 100644 --- a/src/uu/touch/src/touch.rs +++ b/src/uu/touch/src/touch.rs @@ -15,6 +15,7 @@ use chrono::{ use clap::builder::{PossibleValue, ValueParser}; use clap::{Arg, ArgAction, ArgGroup, ArgMatches, Command}; use filetime::{FileTime, set_file_times, set_symlink_file_times}; +use jiff::{Timestamp, Zoned}; use std::borrow::Cow; use std::ffi::OsString; use std::fs::{self, File}; @@ -588,7 +589,7 @@ fn stat(path: &Path, follow: bool) -> std::io::Result<(FileTime, FileTime)> { )) } -fn parse_date(_ref_time: DateTime, s: &str) -> Result { +fn parse_date(ref_time: DateTime, s: &str) -> Result { // This isn't actually compatible with GNU touch, but there doesn't seem to // be any simple specification for what format this parameter allows and I'm // not about to implement GNU parse_datetime. @@ -638,14 +639,35 @@ fn parse_date(_ref_time: DateTime, s: &str) -> Result