hroptatyr / dateutils

nifty command line date and time utilities; fast date calculations and conversion in the shell
http://www.fresse.org/dateutils/
Other
616 stars 42 forks source link

dateconv: -S does not correctly substitute the input date with the new format #98

Closed Earnestly closed 5 years ago

Earnestly commented 5 years ago

dateconv works when not using -S:

$ echo "foo 02/24/19 22:41:40 bar" | dateconv -i '%D %T' -f '%F %T'
2019-01-19 22:41:40
$

When using -S the input date is not properly substituted:

$ echo "foo 02/24/19 22:41:40 bar" | dateconv -i '%D %T' -f '%F %T' -S
foo 02/24/2019-01-19 22:41:40 bar
$

I would have expected the following instead:

$ echo "foo 02/24/19 22:41:40 bar" | dateconv -i '%D %T' -f '%F %T' -S
foo 2019-01-19 22:41:40 bar
$
hroptatyr commented 5 years ago

Hi Earnest, thanks for the report. However, notice how %D in dateutils is different from SU's (or C99's) specification. The rationale is that dateutils only covers ISO formats and uses the remaining characters freely and sometimes differently. %D is needed for ISO year-day dates, as in 2019-019, the 19th day of 2019, a format supported in time.h with no representation in strftime (or strptime).

In your example 19 is picked up as such, and the year comes from the base date (defaults to today) since it's not specified on the line.

$ echo "foo 02/24/19 22:41:40 bar" | dateconv -S -i '%m/%d/%y %T' -f '%F %T'
foo 2019-02-24 22:41:40 bar

should be what you're after.

Earnestly commented 5 years ago

Ah, that's fair then. I was indeed assuming strftime notation.