Closed akx closed 7 months ago
@jun66j5 Could you take a review look at this? Thank you.
LGTM. Thanks!
Confirmed time delta formatting not returning empty string by the following snippet:
from datetime import timedelta
from babel import dates, localedata
for l in sorted(localedata.locale_identifiers()):
for delta in (
timedelta(seconds=1), timedelta(minutes=1), timedelta(hours=1),
timedelta(days=1), timedelta(days=30), timedelta(days=365),
):
for f in ('narrow', 'short', 'long'):
kwargs = {'delta': delta, 'format': f, 'locale': l}
rv = dates.format_timedelta(**kwargs)
if not rv:
print(repr(kwargs))
Also, long format with ja locale had the same issue but it goes away:
>>> dates.format_timedelta(delta=timedelta(seconds=1), format='short', locale='ja')
'1 秒'
>>> dates.format_timedelta(delta=timedelta(seconds=60), format='short', locale='ja')
'1 分'
>>> dates.format_timedelta(delta=timedelta(seconds=3600), format='short', locale='ja')
'1 時間'
>>> dates.format_timedelta(delta=timedelta(days=1), format='short', locale='ja')
'1 日'
>>> dates.format_timedelta(delta=timedelta(days=30), format='short', locale='ja')
'1 か月'
>>> dates.format_timedelta(delta=timedelta(days=365), format='short', locale='ja')
'1 年'
>>> dates.format_timedelta(delta=timedelta(seconds=1), format='long', locale='ja')
''
>>> dates.format_timedelta(delta=timedelta(seconds=60), format='long', locale='ja')
''
>>> dates.format_timedelta(delta=timedelta(seconds=3600), format='long', locale='ja')
''
>>> dates.format_timedelta(delta=timedelta(days=1), format='long', locale='ja')
''
>>> dates.format_timedelta(delta=timedelta(days=30), format='long', locale='ja')
''
>>> dates.format_timedelta(delta=timedelta(days=365), format='long', locale='ja')
''
>>> dates.format_timedelta(delta=timedelta(seconds=1), format='short', locale='ja')
'1 秒'
>>> dates.format_timedelta(delta=timedelta(seconds=60), format='short', locale='ja')
'1 分'
>>> dates.format_timedelta(delta=timedelta(seconds=3600), format='short', locale='ja')
'1 時間'
>>> dates.format_timedelta(delta=timedelta(days=1), format='short', locale='ja')
'1 日'
>>> dates.format_timedelta(delta=timedelta(days=30), format='short', locale='ja')
'1 か月'
>>> dates.format_timedelta(delta=timedelta(days=365), format='short', locale='ja')
'1 年'
>>> dates.format_timedelta(delta=timedelta(seconds=1), format='long', locale='ja')
'1 秒'
>>> dates.format_timedelta(delta=timedelta(seconds=60), format='long', locale='ja')
'1 分'
>>> dates.format_timedelta(delta=timedelta(seconds=3600), format='long', locale='ja')
'1 時間'
>>> dates.format_timedelta(delta=timedelta(days=1), format='long', locale='ja')
'1 日'
>>> dates.format_timedelta(delta=timedelta(days=30), format='long', locale='ja')
'1 か月'
>>> dates.format_timedelta(delta=timedelta(days=365), format='long', locale='ja')
'1 年'
Fixes #892