METADATA 22 KB

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