Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions humanfriendly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
dict(divider=1e-3, singular='millisecond', plural='milliseconds', abbreviations=['ms']),
dict(divider=1, singular='second', plural='seconds', abbreviations=['s', 'sec', 'secs']),
dict(divider=60, singular='minute', plural='minutes', abbreviations=['m', 'min', 'mins']),
dict(divider=60 * 60, singular='hour', plural='hours', abbreviations=['h']),
dict(divider=60 * 60, singular='hour', plural='hours', abbreviations=['h', 'hr', 'hrs']),
dict(divider=60 * 60 * 24, singular='day', plural='days', abbreviations=['d']),
dict(divider=60 * 60 * 24 * 7, singular='week', plural='weeks', abbreviations=['w']),
dict(divider=60 * 60 * 24 * 7 * 52, singular='year', plural='years', abbreviations=['y']))
Expand Down Expand Up @@ -483,7 +483,7 @@ def parse_timespan(timespan):
- ms, millisecond, milliseconds
- s, sec, secs, second, seconds
- m, min, mins, minute, minutes
- h, hour, hours
- h, hr, hrs, hour, hours
- d, day, days
- w, week, weeks
- y, year, years
Expand Down
10 changes: 10 additions & 0 deletions humanfriendly/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,16 @@ def test_format_timespan(self):
then = now - datetime.timedelta(hours=23)
assert '23 hours' == format_timespan(now - then)

def test_parse_timespan_hour_abbreviations(self):
"""Accept hour abbreviations without changing existing aliases."""
for unit in ('h', 'hr', 'hrs', 'hour', 'hours'):
for spelling in (unit, unit.upper()):
self.assertEqual(0, parse_timespan('0' + spelling))
self.assertEqual(3600, parse_timespan('1 ' + spelling))
self.assertEqual(9000, parse_timespan('2.5' + spelling))
with self.assertRaises(InvalidTimespan):
parse_timespan('1 hrss')

def test_parse_timespan(self):
"""Test :func:`humanfriendly.parse_timespan()`."""
self.assertEqual(0, parse_timespan('0'))
Expand Down