Skip to content

Commit cd80f63

Browse files
wtcpythoncakebaker
authored andcommitted
touch: parse unpadded dates in local time
1 parent 403aafc commit cd80f63

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/uu/touch/src/touch.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@ mod format {
126126
pub(crate) const YYYYMMDDHHMMSS: &str = "%Y-%m-%d %H:%M:%S.%f";
127127
// "%Y-%m-%d %H:%M:%S" 12 chars
128128
pub(crate) const YYYYMMDDHHMMS: &str = "%Y-%m-%d %H:%M:%S";
129-
// "%Y-%m-%d %H:%M" 12 chars
130-
// Used for example in tests/touch/no-rights.sh
131-
pub(crate) const YYYY_MM_DD_HH_MM: &str = "%Y-%m-%d %H:%M";
132129
// "%Y%m%d%H%M" 12 chars
133130
pub(crate) const YYYYMMDDHHMM: &str = "%Y%m%d%H%M";
134131
// "%Y-%m-%d %H:%M +offset"
@@ -765,7 +762,6 @@ fn parse_date(ref_zoned: Zoned, s: &str) -> Result<FileTime, TouchError> {
765762
for fmt in [
766763
format::YYYYMMDDHHMMS,
767764
format::YYYYMMDDHHMMSS,
768-
format::YYYY_MM_DD_HH_MM,
769765
format::YYYYMMDDHHMM_OFFSET,
770766
] {
771767
if let Ok(parsed) = strtime::parse(fmt, s)

tests/by-util/test_touch.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,22 @@ fn test_touch_set_date7() {
622622
assert_eq!(mtime, expected);
623623
}
624624

625+
#[test]
626+
fn test_touch_set_date_without_leading_zeroes() {
627+
let (at, mut ucmd) = at_and_ucmd!();
628+
let file = "test_touch_set_date_without_leading_zeroes";
629+
630+
ucmd.env("TZ", "UTC-8")
631+
.args(&["-d", "2026-6-27 13:12", file])
632+
.succeeds()
633+
.no_stderr();
634+
635+
let expected = FileTime::from_unix_time(1_782_537_120, 0);
636+
let (atime, mtime) = get_file_times(&at, file);
637+
assert_eq!(atime, expected);
638+
assert_eq!(mtime, expected);
639+
}
640+
625641
/// Regression test for https://github.com/uutils/coreutils/issues/11804
626642
///
627643
/// Setting a pre-epoch date like `0000-01-01` used to panic on 32-bit targets

0 commit comments

Comments
 (0)