Class
zope.i18n.locales.LocaleDates

Simple ILocaleDates implementation that can inherit data from other locales.

Examples:

>>> from zope.i18n.tests.test_formats import LocaleCalendarStub as Stub
>>> from datetime import datetime, date, time
>>> dates = LocaleDates()
>>> cal = LocaleCalendar('gregorian')
>>> cal.months = Stub.months
>>> cal.days = Stub.days
>>> cal.am = Stub.am
>>> cal.pm = Stub.pm
>>> cal.eras = Stub.eras
>>> cal.week = {'firstDay': 1, 'minDays': 1}
>>> dates.calendars = {'gregorian': cal}

Setting up and accessing date format through a specific length (very common scenario):

>>> fulllength = LocaleFormatLength()
>>> format = LocaleFormat()
>>> format.pattern = u'EEEE, d. MMMM yyyy'
>>> fulllength.formats = {None: format}

>>> mediumlength = LocaleFormatLength()
>>> format = LocaleFormat()
>>> format.pattern = u'dd.MM.yyyy'
>>> mediumlength.formats = {None: format}

>>> cal.dateFormats = {'full': fulllength, 'medium': mediumlength}
>>> cal.defaultDateFormat = 'medium'

>>> formatter = dates.getFormatter('date')
>>> formatter.format(date(2004, 02, 04))
u'04.02.2004'

>>> formatter = dates.getFormatter('date', length='full')
>>> formatter.format(date(2004, 02, 04))
u'Mittwoch, 4. Februar 2004'

Let's also test the time formatter:

>>> fulllength = LocaleFormatLength()
>>> format = LocaleFormat()
>>> format.pattern = u"H:mm' Uhr 'z"
>>> fulllength.formats = {None: format}

>>> mediumlength = LocaleFormatLength()
>>> format = LocaleFormat()
>>> format.pattern = u'HH:mm:ss'
>>> mediumlength.formats = {None: format}

>>> cal.timeFormats = {'full': fulllength, 'medium': mediumlength}
>>> cal.defaultTimeFormat = 'medium'

>>> formatter = dates.getFormatter('time')
>>> formatter.format(time(12, 15, 00))
u'12:15:00'

>>> formatter = dates.getFormatter('time', length='full')
>>> formatter.format(time(12, 15, 00))
u'12:15 Uhr +000'

The datetime formatter is a bit special, since it is constructed from the other two:

>>> length = LocaleFormatLength()
>>> format = LocaleFormat()
>>> format.pattern = u'{1} {0}'
>>> length.formats = {None: format}
>>> cal.dateTimeFormats = {None: length}

>>> formatter = dates.getFormatter('dateTime')
>>> formatter.format(datetime(2004, 02, 04, 12, 15, 00))
u'04.02.2004 12:15:00'

>>> formatter = dates.getFormatter('dateTime', length='full')
>>> formatter.format(datetime(2004, 02, 04, 12, 15, 00))
u'Mittwoch, 4. Februar 2004 12:15 Uhr +000'

Finally, we'll test some invalid input:

>>> dates.getFormatter('timeDate')
Traceback (most recent call last):
ValueError: Invalid category: timeDate

>>> dates.getFormatter('date', length='superlong')
Traceback (most recent call last):
ValueError: Invalid format length: superlong

>>> dates.getFormatter('date', calendar='irish-catholic')
Traceback (most recent call last):
ValueError: Invalid calendar: irish-catholic

Base classes

Implemented Interfaces

Attributes/Properties

There are no attributes in this class.

Methods

Known Subclasses

There are no known subclasses.