Skip to content

touch: Incorrect "months ago" calculation with -d options #10185

@sylvestre

Description

@sylvestre

touch: Incorrect "months ago" calculation with -d options

Component

touch

Description

When using touch -d "X months ago", uutils touch calculates the date differently from GNU coreutils, resulting in a 1-day discrepancy.

Test / Reproduction Steps

$ touch -d "2025-12-30" /tmp/date
$ touch -r /tmp/date -d "1 month ago" /tmp/t; stat t
# ...
Access: 2025-11-30 00:00:00.000000000 +0000
Modify: 2025-11-30 00:00:00.000000000 +0000

$ coreutils touch -r /tmp/date -d "1 month ago" /tmp/tt; stat tt
# ...
Access: 2025-11-29 00:00:00.000000000 +0000
Modify: 2025-11-29 00:00:00.000000000 +0000

Impact

Files may be modified with unintended dates, breaking compatibility with GNU coreutils.

Recommendations

Fix the relative month calculation algorithm to match GNU's implementation using proper calendar month arithmetic.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions