diff options
author | Christopher Lenz <cmlenz@gmail.com> | 2008-07-15 16:02:17 +0000 |
---|---|---|
committer | Christopher Lenz <cmlenz@gmail.com> | 2008-07-15 16:02:17 +0000 |
commit | 77b35a7eca5268e1e87c7e9c49f98088bd0223c2 (patch) | |
tree | 455af7f7a74c79181a2fb05a4f34ef2d0f10ff87 /babel/dates.py | |
parent | 47c72c40d21f9e34d572633cb45344bfc0a58fb1 (diff) | |
download | babel-77b35a7eca5268e1e87c7e9c49f98088bd0223c2.tar.gz |
The `format_timedelta` function now returns, for example, “1 day” instead of “0 days” if the granularity is `day` and the delta is less than a day but greater than zero.
Diffstat (limited to 'babel/dates.py')
-rw-r--r-- | babel/dates.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/babel/dates.py b/babel/dates.py index 0455787..dc60209 100644 --- a/babel/dates.py +++ b/babel/dates.py @@ -613,7 +613,7 @@ def format_timedelta(delta, granularity='second', threshold=.85, locale=LC_TIME) >>> format_timedelta(timedelta(hours=3), granularity='day', ... locale='en_US') - u'0 days' + u'1 day' The threshold parameter can be used to determine at which value the presentation switches to the next higher unit. A higher threshold factor @@ -643,6 +643,8 @@ def format_timedelta(delta, granularity='second', threshold=.85, locale=LC_TIME) for unit, secs_per_unit in TIMEDELTA_UNITS: value = abs(seconds) / secs_per_unit if value >= threshold or unit == granularity: + if unit == granularity and value > 0: + value = max(1, value) value = int(round(value)) plural_form = locale.plural_form(value) pattern = locale._data['unit_patterns'][unit][plural_form] |