From: Christopher Lenz Date: Fri, 18 Jul 2008 13:38:02 +0000 (+0000) Subject: Add `timedelta` function to the `Format` support class. X-Git-Tag: 1.0~286 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b74673665e6426a7f829d285eeca476dbb1e0788;p=thirdparty%2Fbabel.git Add `timedelta` function to the `Format` support class. --- diff --git a/babel/support.py b/babel/support.py index b07a474c..c08ec221 100644 --- a/babel/support.py +++ b/babel/support.py @@ -17,7 +17,7 @@ in applications. .. note: the code in this module is not used by Babel itself """ -from datetime import date, datetime, time +from datetime import date, datetime, time, timedelta import gettext try: @@ -26,7 +26,8 @@ except NameError: from sets import set from babel.core import Locale -from babel.dates import format_date, format_datetime, format_time, LC_TIME +from babel.dates import format_date, format_datetime, format_time, \ + format_timedelta, LC_TIME from babel.numbers import format_number, format_decimal, format_currency, \ format_percent, format_scientific, LC_NUMERIC from babel.util import UTC @@ -91,6 +92,18 @@ class Format(object): """ return format_time(time, format, tzinfo=self.tzinfo, locale=self.locale) + def timedelta(self, delta, granularity='second', threshold=.85): + """Return a time delta according to the rules of the given locale. + + >>> fmt = Format('en_US') + >>> fmt.timedelta(timedelta(weeks=11)) + u'3 months' + + :see: `babel.dates.format_timedelta` + """ + return format_timedelta(delta, granularity=granularity, + threshold=threshold, locale=self.locale) + def number(self, number): """Return an integer number formatted for the locale.