Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

touch: -t YYMMDDhhmm leads to incorrect year if YY > 68 #7280

Open
cakebaker opened this issue Feb 7, 2025 · 3 comments · May be fixed by #7378
Open

touch: -t YYMMDDhhmm leads to incorrect year if YY > 68 #7280

cakebaker opened this issue Feb 7, 2025 · 3 comments · May be fixed by #7378
Labels

Comments

@cakebaker
Copy link
Contributor

If a two-digit year is specified with -t, GNU touch uses the 19-prefix if the year is greater than 68, whereas uutils touch uses 20.

$ touch -t 6801010000 a
$ ls -l a
-rw-r--r-- 1 dho dho 0 Jan  1  2068 a
$ touch -t 6901010000 a
$ ls -l a
-rw-r--r-- 1 dho dho 0 Jan  1  1969 a


$ cargo run -q touch -t 6801010000 a
$ ls -l a
-rw-r--r-- 1 dho dho 0 Jan  1  2068 a
$ cargo run -q touch -t 6901010000 a
$ ls -l a
-rw-r--r-- 1 dho dho 0 Jan  1  2069 a
@RenjiSann
Copy link
Collaborator

That's a very specific issue there 🧐

I'm curious of why did GNU decided to change the behavior between 68-69 specifically

@cakebaker
Copy link
Contributor Author

I don't know what the reason is but the behavior is documented:

If the year is specified with only two digits, then cc is 20 for years in the range 0 … 68, and 19 for years in 69 … 99.

My guess is that it is related to its obsolete syntax:

[...] if there are two or more files and the first file is of the form ‘mmddhhmm[yy]’ and this would be a valid argument to the -t option (if the yy, if any, were moved to the front), and if the represented year is in the range 1969–1999, that argument is interpreted as the time for the other files instead of as a file name.

@RenjiSann RenjiSann added the good first issue For newcomers! label Feb 26, 2025
Carreau pushed a commit to Carreau/coreutils that referenced this issue Mar 2, 2025
When using `touch -t` with a 2 digit year, the year is interpreted as
a relative year to 2000.

When the year is 68 or less, it should be interpreted as 20xx.
When the year is 69 or more, it should be interpreted as 19xx.

This is the behavior of GNU `touch`.

fixes uutilsgh-7280

Arguably 2 digits years should be deprecated as we
are already closer to 2069, than 1969.
Carreau pushed a commit to Carreau/coreutils that referenced this issue Mar 2, 2025
When using `touch -t` with a 2 digit year, the year is interpreted as
a relative year to 2000.

When the year is 68 or less, it should be interpreted as 20xx.
When the year is 69 or more, it should be interpreted as 19xx.

This is the behavior of GNU `touch`.

fixes uutilsgh-7280

Arguably 2 digits years should be deprecated as we
are already closer to 2069, than 1969.
Carreau pushed a commit to Carreau/coreutils that referenced this issue Mar 2, 2025
When using `touch -t` with a 2 digit year, the year is interpreted as
a relative year to 2000.

When the year is 68 or less, it should be interpreted as 20xx.
When the year is 69 or more, it should be interpreted as 19xx.

This is the behavior of GNU `touch`.

fixes uutilsgh-7280

Arguably 2 digits years should be deprecated as we
are already closer to 2069, than 1969.
@Carreau Carreau linked a pull request Mar 2, 2025 that will close this issue
@Carreau
Copy link

Carreau commented Mar 2, 2025

I've attempted a fix in #7378

Carreau pushed a commit to Carreau/coreutils that referenced this issue Mar 3, 2025
When using `touch -t` with a 2 digit year, the year is interpreted as
a relative year to 2000.

When the year is 68 or less, it should be interpreted as 20xx.
When the year is 69 or more, it should be interpreted as 19xx.

This is the behavior of GNU `touch`.

fixes uutilsgh-7280

Arguably 2 digits years should be deprecated as we
are already closer to 2069, than 1969.
Carreau pushed a commit to Carreau/coreutils that referenced this issue Mar 3, 2025
When using `touch -t` with a 2 digit year, the year is interpreted as
a relative year to 2000.

When the year is 68 or less, it should be interpreted as 20xx.
When the year is 69 or more, it should be interpreted as 19xx.

This is the behavior of GNU `touch`.

fixes uutilsgh-7280

Arguably 2 digits years should be deprecated as we
are already closer to 2069, than 1969.
sylvestre pushed a commit to Carreau/coreutils that referenced this issue Mar 4, 2025
When using `touch -t` with a 2 digit year, the year is interpreted as
a relative year to 2000.

When the year is 68 or less, it should be interpreted as 20xx.
When the year is 69 or more, it should be interpreted as 19xx.

This is the behavior of GNU `touch`.

fixes uutilsgh-7280

Arguably 2 digits years should be deprecated as we
are already closer to 2069, than 1969.
RenjiSann pushed a commit to Carreau/coreutils that referenced this issue Mar 10, 2025
When using `touch -t` with a 2 digit year, the year is interpreted as
a relative year to 2000.

When the year is 68 or less, it should be interpreted as 20xx.
When the year is 69 or more, it should be interpreted as 19xx.

This is the behavior of GNU `touch`.

fixes uutilsgh-7280

Arguably 2 digits years should be deprecated as we
are already closer to 2069, than 1969.
Carreau pushed a commit to Carreau/coreutils that referenced this issue Mar 12, 2025
When using `touch -t` with a 2 digit year, the year is interpreted as
a relative year to 2000.

When the year is 68 or less, it should be interpreted as 20xx.
When the year is 69 or more, it should be interpreted as 19xx.

This is the behavior of GNU `touch`.

fixes uutilsgh-7280

Arguably 2 digits years should be deprecated as we
are already closer to 2069, than 1969.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants