# HG changeset patch # User cmlenz # Date 1187183545 0 # Node ID f9f6f740b595333fe14590e643f5821fab3b20ad # Parent fd9abff952f5b838fe3850a3c17b5f11f7634bc9 Added examples for using `get_timezone_name` to documentation. diff --git a/babel/dates.py b/babel/dates.py --- a/babel/dates.py +++ b/babel/dates.py @@ -367,7 +367,7 @@ if dt_or_tzinfo is None or isinstance(dt_or_tzinfo, (int, long)): dt = None tzinfo = UTC - elif isinstance(dt_or_tzinfo, (datetime, time)): + elif isinstance(dt_or_tzinfo, (date, time)): dt = dt_or_tzinfo if dt.tzinfo is not None: tzinfo = dt.tzinfo diff --git a/doc/dates.txt b/doc/dates.txt --- a/doc/dates.txt +++ b/doc/dates.txt @@ -197,7 +197,7 @@ +----------+--------+--------------------------------------------------------+ -Time-Zone Support +Time-zone Support ================= Many of the verbose time formats include the time-zone, but time-zone @@ -243,6 +243,43 @@ .. _`pytz`: http://pytz.sourceforge.net/ +Localized Time-zone Names +------------------------- + +While the ``Locale`` class provides access to various locale display names +related to time-zones, the process of building a localized name of a time-zone +is actually quite complicated. Babel implements it in separately usable +functions in the ``babel.dates`` module, most importantly the +``get_timezone_name`` function: + +.. code-block:: pycon + + >>> from pytz import timezone + >>> from babel import Locale + >>> from babel.dates import get_timezone_name + + >>> tz = timezone('Europe/Berlin') + >>> get_timezone_name(tz, locale=Locale.parse('pt_PT')) + u'Hor\xe1rio Alemanha' + +You can pass the function either a ``datetime.tzinfo`` object, or a +``datetime.date`` or ``datetime.datetime`` object. If you pass an actual date, +the function will be able to take daylight savings time into account. If you +pass just the time-zone, Babel does not know whether daylight savings time is +in effect, so it uses a generic representation, which is useful for example to +display a list of time-zones to the user. + +.. code-block:: pycon + + >>> from datetime import datetime + + >>> dt = tz.localize(datetime(2007, 8, 15)) + >>> get_timezone_name(dt, locale=Locale.parse('de_DE')) + u'Mitteleurop\xe4ische Sommerzeit' + >>> get_timezone_name(tz, locale=Locale.parse('de_DE')) + u'Deutschland' + + Parsing Dates ============= @@ -251,3 +288,5 @@ .. code-block:: pycon >>> from babel.dates import parse_date, parse_datetime, parse_time + +.. note:: Date/time parsing is not properly implemented yet diff --git a/doc/numbers.txt b/doc/numbers.txt --- a/doc/numbers.txt +++ b/doc/numbers.txt @@ -109,3 +109,5 @@ Traceback (most recent call last): ... NumberFormatError: '2,109,998' is not a valid decimal number + +.. note:: Number parsing is not properly implemented yet