Mercurial > babel > old > babel-test
diff babel/dates.py @ 101:1312ad6b624d
Add wrapper class bundling the various formatting functions bound to a specific locale and time-zone.
author | cmlenz |
---|---|
date | Wed, 13 Jun 2007 08:26:23 +0000 |
parents | 4dcdb1d367ec |
children | 90bf48c74714 |
line wrap: on
line diff
--- a/babel/dates.py +++ b/babel/dates.py @@ -170,7 +170,7 @@ return Locale.parse(locale).time_formats[format] def format_date(date=None, format='medium', locale=LC_TIME): - """Returns a date formatted according to the given pattern. + """Return a date formatted according to the given pattern. >>> d = date(2007, 04, 01) >>> format_date(d, locale='en_US') @@ -209,7 +209,7 @@ def format_datetime(datetime=None, format='medium', tzinfo=None, locale=LC_TIME): - """Returns a date formatted according to the given pattern. + """Return a date formatted according to the given pattern. >>> dt = datetime(2007, 04, 01, 15, 30) >>> format_datetime(dt, locale='en_US') @@ -244,7 +244,7 @@ datetime = datetime.replace(tzinfo=UTC) if tzinfo is not None: datetime = datetime.astimezone(tzinfo) - if hasattr(tzinfo, 'normalize'): + if hasattr(tzinfo, 'normalize'): # pytz datetime = tzinfo.normalize(datetime) locale = Locale.parse(locale) @@ -257,7 +257,7 @@ return parse_pattern(format).apply(datetime, locale) def format_time(time=None, format='medium', tzinfo=None, locale=LC_TIME): - """Returns a time formatted according to the given pattern. + """Return a time formatted according to the given pattern. >>> t = time(15, 30) >>> format_time(t, locale='en_US') @@ -274,8 +274,8 @@ For any pattern requiring the display of the time-zone, the third-party ``pytz`` package is needed to explicitly specify the time-zone: - >>> from pytz import timezone, utc - >>> t = time(15, 30, tzinfo=utc) + >>> from pytz import timezone + >>> t = time(15, 30) >>> format_time(t, format='full', tzinfo=timezone('Europe/Berlin'), ... locale='de_DE') u'17:30 Uhr MESZ' @@ -306,7 +306,7 @@ time = time.replace(tzinfo=UTC) if tzinfo is not None: dt = datetime.combine(date.today(), time).astimezone(tzinfo) - if hasattr(tzinfo, 'normalize'): + if hasattr(tzinfo, 'normalize'): # pytz dt = tzinfo.normalize(dt) time = dt.timetz()