Formatting a time interval in seconds as minutes:seconds
using MacOS ootb /bin/date
works as expected using the "+%M:%S"
format:
# convert 200 seconds to 03:20
date -j -f "%s" 200 "+%M:%S"
# OUTPUT: 03:20
# convert 3595 seconds to 59:55
date -j -f "%s" 3595 "+%M:%S"
# OUTPUT: 59:55
However when the parsed value is more than one hour (3600+ seconds) the format string "+%H:%M:%S"
(and the equivalent "+%T"
) appears to have an off-by-one error:
date -j -f "%s" 3600 "+%H:%M:%S"
# ACTUAL OUTPUT: 02:00:00
# EXPECTED OUTPUT: 01:00:00
The manpage for date
mentions that Parsing is done using strptime(3)
which in turn points to strftime
which says:
%s is replaced by the number of seconds since the Epoch, UTC (see mktime(3)).
According to the above I would expect 3600 to be parsed and formatted as 01:00:00
and NOT as 02:00:00
.
Is there something wrong with the arguments I am passing or is this an implementation bug?