Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datediff duration format spec %0 (and %SPC) for padding to any desired fixed width #119

Open
UNIVAC-Colonel-Panic opened this issue Dec 30, 2020 · 0 comments

Comments

@UNIVAC-Colonel-Panic
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant