Mercurial > babel > old > babel-test
diff babel/dates.py @ 395:b4d207b1522d
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.
author | cmlenz |
---|---|
date | Tue, 15 Jul 2008 16:02:17 +0000 |
parents | 0f7f4226f765 |
children | b283ae0e098d |
line wrap: on
line diff
--- a/babel/dates.py +++ b/babel/dates.py @@ -613,7 +613,7 @@ >>> 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 @@ 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]