METADATA 22 KB

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