Mercurial > babel > old > babel-test
comparison doc/dates.txt @ 255:00b83943f79e
Added examples for using `get_timezone_name` to documentation.
author | cmlenz |
---|---|
date | Wed, 15 Aug 2007 13:12:25 +0000 |
parents | bc22f5aef216 |
children | 0f7f4226f765 |
comparison
equal
deleted
inserted
replaced
254:04936a6812af | 255:00b83943f79e |
---|---|
195 | | | should be used regardless of whether they are in | | 195 | | | should be used regardless of whether they are in | |
196 | | | common use by the locale. | | 196 | | | common use by the locale. | |
197 +----------+--------+--------------------------------------------------------+ | 197 +----------+--------+--------------------------------------------------------+ |
198 | 198 |
199 | 199 |
200 Time-Zone Support | 200 Time-zone Support |
201 ================= | 201 ================= |
202 | 202 |
203 Many of the verbose time formats include the time-zone, but time-zone | 203 Many of the verbose time formats include the time-zone, but time-zone |
204 information is not by default available for the Python ``datetime`` and | 204 information is not by default available for the Python ``datetime`` and |
205 ``time`` objects. The standard library includes only the abstract ``tzinfo`` | 205 ``time`` objects. The standard library includes only the abstract ``tzinfo`` |
241 should be used. | 241 should be used. |
242 | 242 |
243 .. _`pytz`: http://pytz.sourceforge.net/ | 243 .. _`pytz`: http://pytz.sourceforge.net/ |
244 | 244 |
245 | 245 |
246 Localized Time-zone Names | |
247 ------------------------- | |
248 | |
249 While the ``Locale`` class provides access to various locale display names | |
250 related to time-zones, the process of building a localized name of a time-zone | |
251 is actually quite complicated. Babel implements it in separately usable | |
252 functions in the ``babel.dates`` module, most importantly the | |
253 ``get_timezone_name`` function: | |
254 | |
255 .. code-block:: pycon | |
256 | |
257 >>> from pytz import timezone | |
258 >>> from babel import Locale | |
259 >>> from babel.dates import get_timezone_name | |
260 | |
261 >>> tz = timezone('Europe/Berlin') | |
262 >>> get_timezone_name(tz, locale=Locale.parse('pt_PT')) | |
263 u'Hor\xe1rio Alemanha' | |
264 | |
265 You can pass the function either a ``datetime.tzinfo`` object, or a | |
266 ``datetime.date`` or ``datetime.datetime`` object. If you pass an actual date, | |
267 the function will be able to take daylight savings time into account. If you | |
268 pass just the time-zone, Babel does not know whether daylight savings time is | |
269 in effect, so it uses a generic representation, which is useful for example to | |
270 display a list of time-zones to the user. | |
271 | |
272 .. code-block:: pycon | |
273 | |
274 >>> from datetime import datetime | |
275 | |
276 >>> dt = tz.localize(datetime(2007, 8, 15)) | |
277 >>> get_timezone_name(dt, locale=Locale.parse('de_DE')) | |
278 u'Mitteleurop\xe4ische Sommerzeit' | |
279 >>> get_timezone_name(tz, locale=Locale.parse('de_DE')) | |
280 u'Deutschland' | |
281 | |
282 | |
246 Parsing Dates | 283 Parsing Dates |
247 ============= | 284 ============= |
248 | 285 |
249 Babel can also parse date and time information in a locale-sensitive manner: | 286 Babel can also parse date and time information in a locale-sensitive manner: |
250 | 287 |
251 .. code-block:: pycon | 288 .. code-block:: pycon |
252 | 289 |
253 >>> from babel.dates import parse_date, parse_datetime, parse_time | 290 >>> from babel.dates import parse_date, parse_datetime, parse_time |
291 | |
292 .. note:: Date/time parsing is not properly implemented yet |