Skip to content

Commit

Permalink
Merge pull request #357 from catkin/fix-356
Browse files Browse the repository at this point in the history
common: fixing short time formatting
  • Loading branch information
jbohren committed Apr 25, 2016
2 parents b9963df + 63e554c commit 8c0b831
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions catkin_tools/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ def format_time_delta_short(delta):
days, date_str = date_str.split(', ')
hours, minutes, seconds = date_str.split(':')
msg = "" if int(days.split(' ')[0]) == 0 else days + " "
msg += "" if int(hours) == 0 else (hours + ":")
msg += "" if int(minutes) == 0 else (minutes + ":")
msg += ("{0:.1f}" if int(minutes) == 0 else "{0:04.1f}").format(float(seconds))
msg += "" if len(msg) == 0 and int(hours) == 0 else (hours + ":")
msg += "" if len(msg) == 0 and int(minutes) == 0 else (minutes + ":")
msg += ("{0:.1f}" if len(msg) == 0 and int(minutes) == 0 else "{0:04.1f}").format(float(seconds))
return msg

__recursive_build_depends_cache = {}
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,19 @@ def test_get_recursive_build_depends_in_workspace_with_test_depend():

r = common.get_recursive_build_depends_in_workspace(pkg1, ordered_packages)
assert r == ordered_packages[1:], r


def test_format_time_delta_short():
inputs = {
1.45: "1.4",
61.45: "01:01.4",
121.45: "02:01.4",
# this one tests: https://github.com/catkin/catkin_tools/issues/356
3601.45: "1:00:01.4",
3721.45: "1:02:01.4",
7321.45: "2:02:01.4",
93821.45: "1 day 2:03:41.5",
}
for k, v in inputs.items():
f = common.format_time_delta_short(k)
assert f == v, "format_time_delta_short({0}) -> '{1}' != '{2}'".format(k, f, v)

0 comments on commit 8c0b831

Please sign in to comment.