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

ISO weekday numbers: %u differs between 'date' and dateutils (zero-padded), no alternate #46

Closed smemsh closed 8 years ago

smemsh commented 8 years ago

Desire to get the ISO day-in-week number. without zero-pad (it's always a single digit in range 1-7). This is possible with date using %u output format, but there does not appear to be any mechanism in dateutils, and the same format confusingly differs between them (where, elsewhere, it strives to maintains consistency):

 $ dateutils.dseq -f %u 2016-04-02
06

 $ date +%u -d 2016-04-02
6

I looked through all the output formats in the man page but could not find one that was not zero-padded. Really, I don't think zero-padding should ever be present anyways, because there's never two digits in the weekday number, so I don't see why it's there.

In fact, canonical ISO dates are always in a format like this: 2004-W53-6 so there's really no way to construct the official ISO date string using dateutils. There's no format specifier to make one of them, so you'd have to build a composite like so:

dateutils.dseq -f %G-W%V-%u 2016-04-02 | sed 's,.\(.\)$,\1,'

which seems to defeat the purpose of dateutils (i.e., not having to shell out for date generation).

hroptatyr commented 8 years ago

Hi Scott, thanks for this report too. Yes you're absolutely right, I should follow ISO on this one.

I sketched out ISO week dates after, my own, year-month-count-weekday dates and they, for optical balance contain zero padding, both for the count of the weekday within the month and also for the weekday itself.

hroptatyr commented 8 years ago

Fixed in 50ba3b8, thanks again for the report.