datediff duration format spec %0 (and %SPC) for padding to any desired fixed width
UNIVAC-Colonel-Panic opened this issue · 0 comments
UNIVAC-Colonel-Panic commented
UTC date duration is my particular use case - how to zero (or space) pad to fixed width to line up in a column?
Sample code
#!/bin/bash
oldest=1529218800 # approx 2018-06-17
older=1606723200 # approx 2020-11-30
newer=1608796800 # approx 2020-12-24
newest=1609304992 # approx 2020-12-29
datediff -i "%s" -f "%000dd:%0Hh:%0Mm:%0Ss" $oldest $older
datediff -i "%s" -f "%000dd:%0Hh:%0Mm:%0Ss" $older $newer
datediff -i "%s" -f "%000dd:%0Hh:%0Mm:%0Ss" $newer $newest
Actual output from above:
897d:01h:00m:00s
24d:00h:00m:00s
05d:21h:09m:52s
Goal is to pad the number of days to be a fixed width of three digits:
897d:01h:00m:00s
024d:00h:00m:00s
005d:21h:09m:52s
The man datediff
page says %0 is the modifier to pad refined values with zeroes but it seems to only pad out to two character positions vs. one character for each 0
I put in the format spec. If this is working as designed, can this be made as a feature request? It doesn't have to be implemented like in my example -- %000
-- but using whatever method is practical.