changeset 403:3a0cea7b8050

Add `timedelta` function to the `Format` support class.
author cmlenz
date Fri, 18 Jul 2008 13:38:02 +0000
parents 3bfce5e0030d
children 7a3ab3e0dcb0
files babel/support.py
diffstat 1 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/babel/support.py
+++ b/babel/support.py
@@ -17,7 +17,7 @@
 .. 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 @@
     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 @@
         """
         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.
         
Copyright (C) 2012-2017 Edgewall Software