class documentation

class Format(object):

View In Hierarchy

Wrapper class providing the various date and number formatting functions bound to a specific locale and time-zone.

>>> from babel.util import UTC
>>> from datetime import date
>>> fmt = Format('en_US', UTC)
>>> fmt.date(date(2007, 4, 1))
u'Apr 1, 2007'
>>> fmt.decimal(1.2345)
u'1.234'
Method currency Return a number in the given currency formatted for the locale.
Method date Return a date formatted according to the given pattern.
Method datetime Return a date and time formatted according to the given pattern.
Method decimal Return a decimal number formatted for the locale.
Method number Return an integer number formatted for the locale.
Method percent Return a number formatted as percentage for the locale.
Method scientific Return a number formatted using scientific notation for the locale.
Method time Return a time formatted according to the given pattern.
Method timedelta Return a time delta according to the rules of the given locale.
Method __init__ Initialize the formatter.
Instance Variable locale Undocumented
Instance Variable tzinfo Undocumented
def currency(self, number, currency):
Return a number in the given currency formatted for the locale.
def date(self, date=None, format='medium'):

Return a date formatted according to the given pattern.

>>> from datetime import date
>>> fmt = Format('en_US')
>>> fmt.date(date(2007, 4, 1))
u'Apr 1, 2007'
def datetime(self, datetime=None, format='medium'):

Return a date and time formatted according to the given pattern.

>>> from datetime import datetime
>>> from pytz import timezone
>>> fmt = Format('en_US', tzinfo=timezone('US/Eastern'))
>>> fmt.datetime(datetime(2007, 4, 1, 15, 30))
u'Apr 1, 2007, 11:30:00 AM'
def decimal(self, number, format=None):

Return a decimal number formatted for the locale.

>>> fmt = Format('en_US')
>>> fmt.decimal(1.2345)
u'1.234'
def number(self, number):

Return an integer number formatted for the locale.

>>> fmt = Format('en_US')
>>> fmt.number(1099)
u'1,099'
def percent(self, number, format=None):

Return a number formatted as percentage for the locale.

>>> fmt = Format('en_US')
>>> fmt.percent(0.34)
u'34%'
def scientific(self, number):
Return a number formatted using scientific notation for the locale.
def time(self, time=None, format='medium'):

Return a time formatted according to the given pattern.

>>> from datetime import datetime
>>> from pytz import timezone
>>> fmt = Format('en_US', tzinfo=timezone('US/Eastern'))
>>> fmt.time(datetime(2007, 4, 1, 15, 30))
u'11:30:00 AM'
def timedelta(self, delta, granularity='second', threshold=0.85, format='long', add_direction=False):

Return a time delta according to the rules of the given locale.

>>> from datetime import timedelta
>>> fmt = Format('en_US')
>>> fmt.timedelta(timedelta(weeks=11))
u'3 months'
def __init__(self, locale, tzinfo=None):
Initialize the formatter.
Parameters
localethe locale identifier or Locale instance
tzinfothe time-zone info (a tzinfo instance or None)
locale =

Undocumented

tzinfo =

Undocumented