Skip to content

Commit

Permalink
[humanize] pad out duration to align fields
Browse files Browse the repository at this point in the history
Fixes #933
  • Loading branch information
tstack committed Jun 19, 2023
1 parent 4cb695f commit 0083eaf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/base/humanize.time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ duration::to_string() const
amount,
curr_interval->symbol);
retval.insert(0, segment);
if (remaining > 0 && amount < 10 && curr_interval->symbol[0]) {
retval.insert(0, "0");
}
}

if (neg) {
Expand Down
5 changes: 4 additions & 1 deletion src/base/humanize.time.tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ TEST_CASE("duration to_string")
std::string val;

val = humanize::time::duration::from_tv({25 * 60 * 60, 123000}).to_string();
CHECK(val == "1d1h0m0s");
CHECK(val == "1d01h00m00s");
val = humanize::time::duration::from_tv({25 * 60 * 60 + 25 * 60, 123000})
.to_string();
CHECK(val == "1d01h25m00s");
val = humanize::time::duration::from_tv({10, 123000}).to_string();
CHECK(val == "10s123");
val = humanize::time::duration::from_tv({10, 0}).to_string();
Expand Down
2 changes: 1 addition & 1 deletion src/internals/sql-ref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ humanize_duration(*secs*)
.. code-block:: custsqlite

;SELECT humanize_duration(15 * 60)
15m0s
15m00s

To format a sub-second value:

Expand Down

0 comments on commit 0083eaf

Please sign in to comment.