diff --git a/humanfriendly/__init__.py b/humanfriendly/__init__.py index 4c0a333..8ef2d75 100644 --- a/humanfriendly/__init__.py +++ b/humanfriendly/__init__.py @@ -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'])) @@ -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 diff --git a/humanfriendly/tests.py b/humanfriendly/tests.py index 72dad99..9bc35b0 100644 --- a/humanfriendly/tests.py +++ b/humanfriendly/tests.py @@ -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'))