Add a pad_to
option for the chrono format
#37
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Allows a
pad_to
option when outputting in the chrono format.pad_to
can be any of:years
,months
,:days
,:hours
,:minutes
, or:seconds
.When present, zeros will not be stripped for the given unit and all units below it.
e.g.
My use case for this is that I'm outputting a bunch of durations in an HTML table column, and wanted the vertical edges of the times to line up with each other (+/- a character). Some are minutes long, others hours long.
Code
I didn't want to refactor too much or move much around as I'm not sure how you'd prefer for that to happen, so I tried to do this in place, directly replacing the old
gsub(/^(00:)+/, '')
with this injectedtap
. As a result it can probably be considered a bit messy, so if you'd like me to clean it up let me know if there's anything I should or shouldn't move around while refactoring.