Description
By a day, to be exact, but only sometimes. I looked at the tests for touch
and none of them seem to make sure that stuff like -d yesterday
has the right output, which is why this hasn't been detected yet, I guess.
The shell I'm using is Nushell, but I can reproduce in Zsh. OS is Ubuntu (WSL).
I ran touch -d yesterday
at around 10:40 pm ET, both the uutils one and the GNU one. The GNU one correctly set the file's times to yesterday, but the uutils one set the file's times to the current time.
> cargo run -p uu_touch -- -d yesterday testing/foo
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.07s
Running `target/debug/touch -d yesterday testing/foo`
> ^touch -d yesterday testing/bar
> ls -al testing | select name accessed modified
╭─#─┬────name─────┬────accessed────┬────modified────╮
│ 0 │ testing/foo │ 13 seconds ago │ 13 seconds ago │
│ 1 │ testing/bar │ a day ago │ a day ago │
╰───┴─────────────┴────────────────┴────────────────╯
Curiously enough, when I ran it at around 5:47 pm ET, I couldn't reproduce it:
> cargo run -p uu_touch -- -d yesterday testing/foo
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.09s
Running `target/debug/touch -d yesterday testing/foo`
> ^touch -d yesterday testing/bar
> ls -al testing | select name accessed modified
╭─#─┬────name─────┬─accessed──┬─modified──╮
│ 0 │ testing/foo │ a day ago │ a day ago │
│ 1 │ testing/bar │ a day ago │ a day ago │
╰───┴─────────────┴───────────┴───────────╯
-d "1 month ago"
also had the same problem when I ran it at around 5:50 pm ET.
> cargo run -p uu_touch -- -d "1 month ago" testing/foo
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.09s
Running `target/debug/touch -d '1 month ago' testing/foo`
> (ls -al testing/foo).0.accessed
Wed, 10 Jul 2024 17:49:09 -0400 (a month ago)
> ^touch -d "1 month ago" testing/bar
> (ls -al testing/bar).0.accessed
Tue, 9 Jul 2024 17:49:31 -0400 (a month ago)
But when I ran it at around 10:45 pm ET, I couldn't reproduce the problem with -d "1 month ago"
:
> cargo run -p uu_touch -- -d "1 month ago" testing/foo
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.08s
Running `target/debug/touch -d '1 month ago' testing/foo`
> ^touch -d "1 month ago" testing/bar
> ls -al testing | select name accessed modified
╭─#─┬────name─────┬──accessed───┬──modified───╮
│ 0 │ testing/foo │ a month ago │ a month ago │
│ 1 │ testing/bar │ a month ago │ a month ago │
╰───┴─────────────┴─────────────┴─────────────╯
I suspect that this is a problem with using DateTime<Local>
s or something. The -d yesterday
bug happened when I ran it after UTC midnight but before my local midnight. It didn't happen when I ran it after my local midnight but before UTC midnight. The -d "1 month ago"
behavior was the opposite. Perhaps if uutils uses DateTime<Utc>
, that'll help?