uutils / coreutils

Cross-platform Rust rewrite of the GNU coreutils
https://uutils.github.io/
MIT License
17.53k stars 1.26k forks source link

date: date setting format error #6398

Open my4ng opened 4 months ago

my4ng commented 4 months ago

The coreutils version currently uses the parse_datetime crate to parse the date source which parses in YYYYMMDDHHMM and similar formats. However it is not compliant with date:

Usage: date [OPTION]... [+FORMAT]
  or:  date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
Display date and time in the given FORMAT.
With -s, or with [MMDDhhmm[[CC]YY][.ss]], set the date and time.

GNU:

$ date 11111111
Mon 11 Nov 2024 11:11:00 AEDT

coreutils

$ cargo run --release -p uu_date -- 11111111
target/release/date: invalid date '11111111'

Since it is interpreting the first 1111 as the year.

Note: date -s STRING is compliant with GNU the version, only the positional argument format is affected.

RenjiSann commented 3 months ago

So from what I investigated, the program fails on this part of the code

I am not sure of what I say, but it looks like our implementation only supports

date [OPTION]... [+FORMAT]

and not

date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

because the reason the program fails is that there is no + at the start of our 11111111 string.

So we'd need to fix that.

I also note that the +% format fails on coreutils, while it only prints a % in GNU.

dhilst commented 2 weeks ago

I'm working on a date format fix here: https://github.com/uutils/coreutils/pull/6667/