METADATA 22 KB

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