METADATA 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. Metadata-Version: 2.0
  2. Name: pytz
  3. Version: 2021.1
  4. Summary: World timezone definitions, modern and historical
  5. Home-page: http://pythonhosted.org/pytz
  6. Author: Stuart Bishop
  7. Author-email: stuart@stuartbishop.net
  8. Maintainer: Stuart Bishop
  9. Maintainer-email: stuart@stuartbishop.net
  10. License: MIT
  11. Download-URL: https://pypi.org/project/pytz/
  12. Keywords: timezone,tzinfo,datetime,olson,time
  13. Platform: Independent
  14. Classifier: Development Status :: 6 - Mature
  15. Classifier: Intended Audience :: Developers
  16. Classifier: License :: OSI Approved :: MIT License
  17. Classifier: Natural Language :: English
  18. Classifier: Operating System :: OS Independent
  19. Classifier: Programming Language :: Python
  20. Classifier: Programming Language :: Python :: 2
  21. Classifier: Programming Language :: Python :: 2.4
  22. Classifier: Programming Language :: Python :: 2.5
  23. Classifier: Programming Language :: Python :: 2.6
  24. Classifier: Programming Language :: Python :: 2.7
  25. Classifier: Programming Language :: Python :: 3
  26. Classifier: Programming Language :: Python :: 3.1
  27. Classifier: Programming Language :: Python :: 3.2
  28. Classifier: Programming Language :: Python :: 3.3
  29. Classifier: Programming Language :: Python :: 3.4
  30. Classifier: Programming Language :: Python :: 3.5
  31. Classifier: Programming Language :: Python :: 3.6
  32. Classifier: Programming Language :: Python :: 3.7
  33. Classifier: Programming Language :: Python :: 3.8
  34. Classifier: Programming Language :: Python :: 3.9
  35. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  36. pytz - World Timezone Definitions for Python
  37. ============================================
  38. :Author: Stuart Bishop <stuart@stuartbishop.net>
  39. Introduction
  40. ~~~~~~~~~~~~
  41. pytz brings the Olson tz database into Python. This library allows
  42. accurate and cross platform timezone calculations using Python 2.4
  43. or higher. It also solves the issue of ambiguous times at the end
  44. of daylight saving time, which you can read more about in the Python
  45. Library Reference (``datetime.tzinfo``).
  46. Almost all of the Olson timezones are supported.
  47. .. note::
  48. This library differs from the documented Python API for
  49. tzinfo implementations; if you want to create local wallclock
  50. times you need to use the ``localize()`` method documented in this
  51. document. In addition, if you perform date arithmetic on local
  52. times that cross DST boundaries, the result may be in an incorrect
  53. timezone (ie. subtract 1 minute from 2002-10-27 1:00 EST and you get
  54. 2002-10-27 0:59 EST instead of the correct 2002-10-27 1:59 EDT). A
  55. ``normalize()`` method is provided to correct this. Unfortunately these
  56. issues cannot be resolved without modifying the Python datetime
  57. implementation (see PEP-431).
  58. Installation
  59. ~~~~~~~~~~~~
  60. This package can either be installed using ``pip`` or from a tarball using the
  61. standard Python distutils.
  62. If you are installing using ``pip``, you don't need to download anything as the
  63. latest version will be downloaded for you from PyPI::
  64. pip install pytz
  65. If you are installing from a tarball, run the following command as an
  66. administrative user::
  67. python setup.py install
  68. pytz for Enterprise
  69. ~~~~~~~~~~~~~~~~~~~
  70. Available as part of the Tidelift Subscription.
  71. The maintainers of pytz and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. `Learn more. <https://tidelift.com/subscription/pkg/pypi-pytz?utm_source=pypi-pytz&utm_medium=referral&utm_campaign=enterprise&utm_term=repo>`_.
  72. Example & Usage
  73. ~~~~~~~~~~~~~~~
  74. Localized times and date arithmetic
  75. -----------------------------------
  76. >>> from datetime import datetime, timedelta
  77. >>> from pytz import timezone
  78. >>> import pytz
  79. >>> utc = pytz.utc
  80. >>> utc.zone
  81. 'UTC'
  82. >>> eastern = timezone('US/Eastern')
  83. >>> eastern.zone
  84. 'US/Eastern'
  85. >>> amsterdam = timezone('Europe/Amsterdam')
  86. >>> fmt = '%Y-%m-%d %H:%M:%S %Z%z'
  87. This library only supports two ways of building a localized time. The
  88. first is to use the ``localize()`` method provided by the pytz library.
  89. This is used to localize a naive datetime (datetime with no timezone
  90. information):
  91. >>> loc_dt = eastern.localize(datetime(2002, 10, 27, 6, 0, 0))
  92. >>> print(loc_dt.strftime(fmt))
  93. 2002-10-27 06:00:00 EST-0500
  94. The second way of building a localized time is by converting an existing
  95. localized time using the standard ``astimezone()`` method:
  96. >>> ams_dt = loc_dt.astimezone(amsterdam)
  97. >>> ams_dt.strftime(fmt)
  98. '2002-10-27 12:00:00 CET+0100'
  99. Unfortunately using the tzinfo argument of the standard datetime
  100. constructors ''does not work'' with pytz for many timezones.
  101. >>> datetime(2002, 10, 27, 12, 0, 0, tzinfo=amsterdam).strftime(fmt) # /!\ Does not work this way!
  102. '2002-10-27 12:00:00 LMT+0020'
  103. It is safe for timezones without daylight saving transitions though, such
  104. as UTC:
  105. >>> datetime(2002, 10, 27, 12, 0, 0, tzinfo=pytz.utc).strftime(fmt) # /!\ Not recommended except for UTC
  106. '2002-10-27 12:00:00 UTC+0000'
  107. The preferred way of dealing with times is to always work in UTC,
  108. converting to localtime only when generating output to be read
  109. by humans.
  110. >>> utc_dt = datetime(2002, 10, 27, 6, 0, 0, tzinfo=utc)
  111. >>> loc_dt = utc_dt.astimezone(eastern)
  112. >>> loc_dt.strftime(fmt)
  113. '2002-10-27 01:00:00 EST-0500'
  114. This library also allows you to do date arithmetic using local
  115. times, although it is more complicated than working in UTC as you
  116. need to use the ``normalize()`` method to handle daylight saving time
  117. and other timezone transitions. In this example, ``loc_dt`` is set
  118. to the instant when daylight saving time ends in the US/Eastern
  119. timezone.
  120. >>> before = loc_dt - timedelta(minutes=10)
  121. >>> before.strftime(fmt)
  122. '2002-10-27 00:50:00 EST-0500'
  123. >>> eastern.normalize(before).strftime(fmt)
  124. '2002-10-27 01:50:00 EDT-0400'
  125. >>> after = eastern.normalize(before + timedelta(minutes=20))
  126. >>> after.strftime(fmt)
  127. '2002-10-27 01:10:00 EST-0500'
  128. Creating local times is also tricky, and the reason why working with
  129. local times is not recommended. Unfortunately, you cannot just pass
  130. a ``tzinfo`` argument when constructing a datetime (see the next
  131. section for more details)
  132. >>> dt = datetime(2002, 10, 27, 1, 30, 0)
  133. >>> dt1 = eastern.localize(dt, is_dst=True)
  134. >>> dt1.strftime(fmt)
  135. '2002-10-27 01:30:00 EDT-0400'
  136. >>> dt2 = eastern.localize(dt, is_dst=False)
  137. >>> dt2.strftime(fmt)
  138. '2002-10-27 01:30:00 EST-0500'
  139. Converting between timezones is more easily done, using the
  140. standard astimezone method.
  141. >>> utc_dt = utc.localize(datetime.utcfromtimestamp(1143408899))
  142. >>> utc_dt.strftime(fmt)
  143. '2006-03-26 21:34:59 UTC+0000'
  144. >>> au_tz = timezone('Australia/Sydney')
  145. >>> au_dt = utc_dt.astimezone(au_tz)
  146. >>> au_dt.strftime(fmt)
  147. '2006-03-27 08:34:59 AEDT+1100'
  148. >>> utc_dt2 = au_dt.astimezone(utc)
  149. >>> utc_dt2.strftime(fmt)
  150. '2006-03-26 21:34:59 UTC+0000'
  151. >>> utc_dt == utc_dt2
  152. True
  153. You can take shortcuts when dealing with the UTC side of timezone
  154. conversions. ``normalize()`` and ``localize()`` are not really
  155. necessary when there are no daylight saving time transitions to
  156. deal with.
  157. >>> utc_dt = datetime.utcfromtimestamp(1143408899).replace(tzinfo=utc)
  158. >>> utc_dt.strftime(fmt)
  159. '2006-03-26 21:34:59 UTC+0000'
  160. >>> au_tz = timezone('Australia/Sydney')
  161. >>> au_dt = au_tz.normalize(utc_dt.astimezone(au_tz))
  162. >>> au_dt.strftime(fmt)
  163. '2006-03-27 08:34:59 AEDT+1100'
  164. >>> utc_dt2 = au_dt.astimezone(utc)
  165. >>> utc_dt2.strftime(fmt)
  166. '2006-03-26 21:34:59 UTC+0000'
  167. ``tzinfo`` API
  168. --------------
  169. The ``tzinfo`` instances returned by the ``timezone()`` function have
  170. been extended to cope with ambiguous times by adding an ``is_dst``
  171. parameter to the ``utcoffset()``, ``dst()`` && ``tzname()`` methods.
  172. >>> tz = timezone('America/St_Johns')
  173. >>> normal = datetime(2009, 9, 1)
  174. >>> ambiguous = datetime(2009, 10, 31, 23, 30)
  175. The ``is_dst`` parameter is ignored for most timestamps. It is only used
  176. during DST transition ambiguous periods to resolve that ambiguity.
  177. >>> print(tz.utcoffset(normal, is_dst=True))
  178. -1 day, 21:30:00
  179. >>> print(tz.dst(normal, is_dst=True))
  180. 1:00:00
  181. >>> tz.tzname(normal, is_dst=True)
  182. 'NDT'
  183. >>> print(tz.utcoffset(ambiguous, is_dst=True))
  184. -1 day, 21:30:00
  185. >>> print(tz.dst(ambiguous, is_dst=True))
  186. 1:00:00
  187. >>> tz.tzname(ambiguous, is_dst=True)
  188. 'NDT'
  189. >>> print(tz.utcoffset(normal, is_dst=False))
  190. -1 day, 21:30:00
  191. >>> tz.dst(normal, is_dst=False)
  192. datetime.timedelta(0, 3600)
  193. >>> tz.tzname(normal, is_dst=False)
  194. 'NDT'
  195. >>> print(tz.utcoffset(ambiguous, is_dst=False))
  196. -1 day, 20:30:00
  197. >>> tz.dst(ambiguous, is_dst=False)
  198. datetime.timedelta(0)
  199. >>> tz.tzname(ambiguous, is_dst=False)
  200. 'NST'
  201. If ``is_dst`` is not specified, ambiguous timestamps will raise
  202. an ``pytz.exceptions.AmbiguousTimeError`` exception.
  203. >>> print(tz.utcoffset(normal))
  204. -1 day, 21:30:00
  205. >>> print(tz.dst(normal))
  206. 1:00:00
  207. >>> tz.tzname(normal)
  208. 'NDT'
  209. >>> import pytz.exceptions
  210. >>> try:
  211. ... tz.utcoffset(ambiguous)
  212. ... except pytz.exceptions.AmbiguousTimeError:
  213. ... print('pytz.exceptions.AmbiguousTimeError: %s' % ambiguous)
  214. pytz.exceptions.AmbiguousTimeError: 2009-10-31 23:30:00
  215. >>> try:
  216. ... tz.dst(ambiguous)
  217. ... except pytz.exceptions.AmbiguousTimeError:
  218. ... print('pytz.exceptions.AmbiguousTimeError: %s' % ambiguous)
  219. pytz.exceptions.AmbiguousTimeError: 2009-10-31 23:30:00
  220. >>> try:
  221. ... tz.tzname(ambiguous)
  222. ... except pytz.exceptions.AmbiguousTimeError:
  223. ... print('pytz.exceptions.AmbiguousTimeError: %s' % ambiguous)
  224. pytz.exceptions.AmbiguousTimeError: 2009-10-31 23:30:00
  225. Problems with Localtime
  226. ~~~~~~~~~~~~~~~~~~~~~~~
  227. The major problem we have to deal with is that certain datetimes
  228. may occur twice in a year. For example, in the US/Eastern timezone
  229. on the last Sunday morning in October, the following sequence
  230. happens:
  231. - 01:00 EDT occurs
  232. - 1 hour later, instead of 2:00am the clock is turned back 1 hour
  233. and 01:00 happens again (this time 01:00 EST)
  234. In fact, every instant between 01:00 and 02:00 occurs twice. This means
  235. that if you try and create a time in the 'US/Eastern' timezone
  236. the standard datetime syntax, there is no way to specify if you meant
  237. before of after the end-of-daylight-saving-time transition. Using the
  238. pytz custom syntax, the best you can do is make an educated guess:
  239. >>> loc_dt = eastern.localize(datetime(2002, 10, 27, 1, 30, 00))
  240. >>> loc_dt.strftime(fmt)
  241. '2002-10-27 01:30:00 EST-0500'
  242. As you can see, the system has chosen one for you and there is a 50%
  243. chance of it being out by one hour. For some applications, this does
  244. not matter. However, if you are trying to schedule meetings with people
  245. in different timezones or analyze log files it is not acceptable.
  246. The best and simplest solution is to stick with using UTC. The pytz
  247. package encourages using UTC for internal timezone representation by
  248. including a special UTC implementation based on the standard Python
  249. reference implementation in the Python documentation.
  250. The UTC timezone unpickles to be the same instance, and pickles to a
  251. smaller size than other pytz tzinfo instances. The UTC implementation
  252. can be obtained as pytz.utc, pytz.UTC, or pytz.timezone('UTC').
  253. >>> import pickle, pytz
  254. >>> dt = datetime(2005, 3, 1, 14, 13, 21, tzinfo=utc)
  255. >>> naive = dt.replace(tzinfo=None)
  256. >>> p = pickle.dumps(dt, 1)
  257. >>> naive_p = pickle.dumps(naive, 1)
  258. >>> len(p) - len(naive_p)
  259. 17
  260. >>> new = pickle.loads(p)
  261. >>> new == dt
  262. True
  263. >>> new is dt
  264. False
  265. >>> new.tzinfo is dt.tzinfo
  266. True
  267. >>> pytz.utc is pytz.UTC is pytz.timezone('UTC')
  268. True
  269. Note that some other timezones are commonly thought of as the same (GMT,
  270. Greenwich, Universal, etc.). The definition of UTC is distinct from these
  271. other timezones, and they are not equivalent. For this reason, they will
  272. not compare the same in Python.
  273. >>> utc == pytz.timezone('GMT')
  274. False
  275. See the section `What is UTC`_, below.
  276. If you insist on working with local times, this library provides a
  277. facility for constructing them unambiguously:
  278. >>> loc_dt = datetime(2002, 10, 27, 1, 30, 00)
  279. >>> est_dt = eastern.localize(loc_dt, is_dst=True)
  280. >>> edt_dt = eastern.localize(loc_dt, is_dst=False)
  281. >>> print(est_dt.strftime(fmt) + ' / ' + edt_dt.strftime(fmt))
  282. 2002-10-27 01:30:00 EDT-0400 / 2002-10-27 01:30:00 EST-0500
  283. If you pass None as the is_dst flag to localize(), pytz will refuse to
  284. guess and raise exceptions if you try to build ambiguous or non-existent
  285. times.
  286. For example, 1:30am on 27th Oct 2002 happened twice in the US/Eastern
  287. timezone when the clocks where put back at the end of Daylight Saving
  288. Time:
  289. >>> dt = datetime(2002, 10, 27, 1, 30, 00)
  290. >>> try:
  291. ... eastern.localize(dt, is_dst=None)
  292. ... except pytz.exceptions.AmbiguousTimeError:
  293. ... print('pytz.exceptions.AmbiguousTimeError: %s' % dt)
  294. pytz.exceptions.AmbiguousTimeError: 2002-10-27 01:30:00
  295. Similarly, 2:30am on 7th April 2002 never happened at all in the
  296. US/Eastern timezone, as the clocks where put forward at 2:00am skipping
  297. the entire hour:
  298. >>> dt = datetime(2002, 4, 7, 2, 30, 00)
  299. >>> try:
  300. ... eastern.localize(dt, is_dst=None)
  301. ... except pytz.exceptions.NonExistentTimeError:
  302. ... print('pytz.exceptions.NonExistentTimeError: %s' % dt)
  303. pytz.exceptions.NonExistentTimeError: 2002-04-07 02:30:00
  304. Both of these exceptions share a common base class to make error handling
  305. easier:
  306. >>> isinstance(pytz.AmbiguousTimeError(), pytz.InvalidTimeError)
  307. True
  308. >>> isinstance(pytz.NonExistentTimeError(), pytz.InvalidTimeError)
  309. True
  310. A special case is where countries change their timezone definitions
  311. with no daylight savings time switch. For example, in 1915 Warsaw
  312. switched from Warsaw time to Central European time with no daylight savings
  313. transition. So at the stroke of midnight on August 5th 1915 the clocks
  314. were wound back 24 minutes creating an ambiguous time period that cannot
  315. be specified without referring to the timezone abbreviation or the
  316. actual UTC offset. In this case midnight happened twice, neither time
  317. during a daylight saving time period. pytz handles this transition by
  318. treating the ambiguous period before the switch as daylight savings
  319. time, and the ambiguous period after as standard time.
  320. >>> warsaw = pytz.timezone('Europe/Warsaw')
  321. >>> amb_dt1 = warsaw.localize(datetime(1915, 8, 4, 23, 59, 59), is_dst=True)
  322. >>> amb_dt1.strftime(fmt)
  323. '1915-08-04 23:59:59 WMT+0124'
  324. >>> amb_dt2 = warsaw.localize(datetime(1915, 8, 4, 23, 59, 59), is_dst=False)
  325. >>> amb_dt2.strftime(fmt)
  326. '1915-08-04 23:59:59 CET+0100'
  327. >>> switch_dt = warsaw.localize(datetime(1915, 8, 5, 00, 00, 00), is_dst=False)
  328. >>> switch_dt.strftime(fmt)
  329. '1915-08-05 00:00:00 CET+0100'
  330. >>> str(switch_dt - amb_dt1)
  331. '0:24:01'
  332. >>> str(switch_dt - amb_dt2)
  333. '0:00:01'
  334. The best way of creating a time during an ambiguous time period is
  335. by converting from another timezone such as UTC:
  336. >>> utc_dt = datetime(1915, 8, 4, 22, 36, tzinfo=pytz.utc)
  337. >>> utc_dt.astimezone(warsaw).strftime(fmt)
  338. '1915-08-04 23:36:00 CET+0100'
  339. The standard Python way of handling all these ambiguities is not to
  340. handle them, such as demonstrated in this example using the US/Eastern
  341. timezone definition from the Python documentation (Note that this
  342. implementation only works for dates between 1987 and 2006 - it is
  343. included for tests only!):
  344. >>> from pytz.reference import Eastern # pytz.reference only for tests
  345. >>> dt = datetime(2002, 10, 27, 0, 30, tzinfo=Eastern)
  346. >>> str(dt)
  347. '2002-10-27 00:30:00-04:00'
  348. >>> str(dt + timedelta(hours=1))
  349. '2002-10-27 01:30:00-05:00'
  350. >>> str(dt + timedelta(hours=2))
  351. '2002-10-27 02:30:00-05:00'
  352. >>> str(dt + timedelta(hours=3))
  353. '2002-10-27 03:30:00-05:00'
  354. Notice the first two results? At first glance you might think they are
  355. correct, but taking the UTC offset into account you find that they are
  356. actually two hours appart instead of the 1 hour we asked for.
  357. >>> from pytz.reference import UTC # pytz.reference only for tests
  358. >>> str(dt.astimezone(UTC))
  359. '2002-10-27 04:30:00+00:00'
  360. >>> str((dt + timedelta(hours=1)).astimezone(UTC))
  361. '2002-10-27 06:30:00+00:00'
  362. Country Information
  363. ~~~~~~~~~~~~~~~~~~~
  364. A mechanism is provided to access the timezones commonly in use
  365. for a particular country, looked up using the ISO 3166 country code.
  366. It returns a list of strings that can be used to retrieve the relevant
  367. tzinfo instance using ``pytz.timezone()``:
  368. >>> print(' '.join(pytz.country_timezones['nz']))
  369. Pacific/Auckland Pacific/Chatham
  370. The Olson database comes with a ISO 3166 country code to English country
  371. name mapping that pytz exposes as a dictionary:
  372. >>> print(pytz.country_names['nz'])
  373. New Zealand
  374. What is UTC
  375. ~~~~~~~~~~~
  376. 'UTC' is `Coordinated Universal Time`_. It is a successor to, but distinct
  377. from, Greenwich Mean Time (GMT) and the various definitions of Universal
  378. Time. UTC is now the worldwide standard for regulating clocks and time
  379. measurement.
  380. All other timezones are defined relative to UTC, and include offsets like
  381. UTC+0800 - hours to add or subtract from UTC to derive the local time. No
  382. daylight saving time occurs in UTC, making it a useful timezone to perform
  383. date arithmetic without worrying about the confusion and ambiguities caused
  384. by daylight saving time transitions, your country changing its timezone, or
  385. mobile computers that roam through multiple timezones.
  386. .. _Coordinated Universal Time: https://en.wikipedia.org/wiki/Coordinated_Universal_Time
  387. Helpers
  388. ~~~~~~~
  389. There are two lists of timezones provided.
  390. ``all_timezones`` is the exhaustive list of the timezone names that can
  391. be used.
  392. >>> from pytz import all_timezones
  393. >>> len(all_timezones) >= 500
  394. True
  395. >>> 'Etc/Greenwich' in all_timezones
  396. True
  397. ``common_timezones`` is a list of useful, current timezones. It doesn't
  398. contain deprecated zones or historical zones, except for a few I've
  399. deemed in common usage, such as US/Eastern (open a bug report if you
  400. think other timezones are deserving of being included here). It is also
  401. a sequence of strings.
  402. >>> from pytz import common_timezones
  403. >>> len(common_timezones) < len(all_timezones)
  404. True
  405. >>> 'Etc/Greenwich' in common_timezones
  406. False
  407. >>> 'Australia/Melbourne' in common_timezones
  408. True
  409. >>> 'US/Eastern' in common_timezones
  410. True
  411. >>> 'Canada/Eastern' in common_timezones
  412. True
  413. >>> 'Australia/Yancowinna' in all_timezones
  414. True
  415. >>> 'Australia/Yancowinna' in common_timezones
  416. False
  417. Both ``common_timezones`` and ``all_timezones`` are alphabetically
  418. sorted:
  419. >>> common_timezones_dupe = common_timezones[:]
  420. >>> common_timezones_dupe.sort()
  421. >>> common_timezones == common_timezones_dupe
  422. True
  423. >>> all_timezones_dupe = all_timezones[:]
  424. >>> all_timezones_dupe.sort()
  425. >>> all_timezones == all_timezones_dupe
  426. True
  427. ``all_timezones`` and ``common_timezones`` are also available as sets.
  428. >>> from pytz import all_timezones_set, common_timezones_set
  429. >>> 'US/Eastern' in all_timezones_set
  430. True
  431. >>> 'US/Eastern' in common_timezones_set
  432. True
  433. >>> 'Australia/Victoria' in common_timezones_set
  434. False
  435. You can also retrieve lists of timezones used by particular countries
  436. using the ``country_timezones()`` function. It requires an ISO-3166
  437. two letter country code.
  438. >>> from pytz import country_timezones
  439. >>> print(' '.join(country_timezones('ch')))
  440. Europe/Zurich
  441. >>> print(' '.join(country_timezones('CH')))
  442. Europe/Zurich
  443. Internationalization - i18n/l10n
  444. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  445. Pytz is an interface to the IANA database, which uses ASCII names. The `Unicode Consortium's Unicode Locales (CLDR) <http://cldr.unicode.org>`_
  446. project provides translations. Thomas Khyn's
  447. `l18n <https://pypi.org/project/l18n/>`_ package can be used to access
  448. these translations from Python.
  449. License
  450. ~~~~~~~
  451. MIT license.
  452. This code is also available as part of Zope 3 under the Zope Public
  453. License, Version 2.1 (ZPL).
  454. I'm happy to relicense this code if necessary for inclusion in other
  455. open source projects.
  456. Latest Versions
  457. ~~~~~~~~~~~~~~~
  458. This package will be updated after releases of the Olson timezone
  459. database. The latest version can be downloaded from the `Python Package
  460. Index <https://pypi.org/project/pytz/>`_. The code that is used
  461. to generate this distribution is hosted on launchpad.net and available
  462. using git::
  463. git clone https://git.launchpad.net/pytz
  464. A mirror on github is also available at https://github.com/stub42/pytz
  465. Announcements of new releases are made on
  466. `Launchpad <https://launchpad.net/pytz>`_, and the
  467. `Atom feed <http://feeds.launchpad.net/pytz/announcements.atom>`_
  468. hosted there.
  469. Bugs, Feature Requests & Patches
  470. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  471. Bugs can be reported using `Launchpad Bugs <https://bugs.launchpad.net/pytz>`_.
  472. Security Issues
  473. ~~~~~~~~~~~~~~~
  474. Reports about security issues can be made via `Tidelift <https://tidelift.com/security>`_.
  475. Issues & Limitations
  476. ~~~~~~~~~~~~~~~~~~~~
  477. - Offsets from UTC are rounded to the nearest whole minute, so timezones
  478. such as Europe/Amsterdam pre 1937 will be up to 30 seconds out. This
  479. is a limitation of the Python datetime library.
  480. - If you think a timezone definition is incorrect, I probably can't fix
  481. it. pytz is a direct translation of the Olson timezone database, and
  482. changes to the timezone definitions need to be made to this source.
  483. If you find errors they should be reported to the time zone mailing
  484. list, linked from http://www.iana.org/time-zones.
  485. Further Reading
  486. ~~~~~~~~~~~~~~~
  487. More info than you want to know about timezones:
  488. http://www.twinsun.com/tz/tz-link.htm
  489. Contact
  490. ~~~~~~~
  491. Stuart Bishop <stuart@stuartbishop.net>