METADATA 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. Metadata-Version: 2.1
  2. Name: tzlocal
  3. Version: 5.3.1
  4. Summary: tzinfo object for the local timezone
  5. Author-email: Lennart Regebro <regebro@gmail.com>
  6. License: MIT
  7. Project-URL: Source code, https://github.com/regebro/tzlocal
  8. Project-URL: Changelog, https://github.com/regebro/tzlocal/blob/master/CHANGES.txt
  9. Project-URL: Issue tracker, https://github.com/regebro/tzlocal/issues
  10. Keywords: timezone
  11. Classifier: Development Status :: 5 - Production/Stable
  12. Classifier: License :: OSI Approved :: MIT License
  13. Classifier: Operating System :: Microsoft :: Windows
  14. Classifier: Operating System :: Unix
  15. Classifier: Operating System :: MacOS :: MacOS X
  16. Classifier: Typing :: Typed
  17. Classifier: Programming Language :: Python :: 3.9
  18. Classifier: Programming Language :: Python :: 3.10
  19. Classifier: Programming Language :: Python :: 3.11
  20. Classifier: Programming Language :: Python :: 3.12
  21. Classifier: Programming Language :: Python :: 3.13
  22. Requires-Python: >=3.9
  23. Description-Content-Type: text/x-rst
  24. License-File: LICENSE.txt
  25. Requires-Dist: tzdata ; platform_system == "Windows"
  26. Provides-Extra: devenv
  27. Requires-Dist: pytest (>=4.3) ; extra == 'devenv'
  28. Requires-Dist: pytest-mock (>=3.3) ; extra == 'devenv'
  29. Requires-Dist: pytest-cov ; extra == 'devenv'
  30. Requires-Dist: check-manifest ; extra == 'devenv'
  31. Requires-Dist: zest.releaser ; extra == 'devenv'
  32. tzlocal
  33. =======
  34. API CHANGE!
  35. -----------
  36. With version 3.0 of tzlocal, tzlocal no longer returned `pytz` objects, but
  37. `zoneinfo` objects, which has a different API. Since 4.0, it now restored
  38. partial compatibility for `pytz` users through Paul Ganssle's
  39. `pytz_deprecation_shim`.
  40. tzlocal 4.0 also adds an official function `get_localzone_name()` to get only
  41. the timezone name, instead of a timezone object. On unix, it can raise an
  42. error if you don't have a timezone name configured, where `get_localzone()`
  43. will succeed, so only use that if you need the timezone name.
  44. 4.0 also adds way more information on what is going wrong in your
  45. configuration when the configuration files are unclear or contradictory.
  46. Version 5.0 removes the `pytz_deprecation_shim`, and now only returns
  47. `zoneinfo` objects, like verion 3.0 did. If you need `pytz` objects, you have
  48. to stay on version 4.0. If there are bugs in version 4.0, I will release
  49. updates, but there will be no further functional changes on the 4.x branch.
  50. Info
  51. ----
  52. This Python module returns the `IANA time zone name
  53. <https://www.iana.org/time-zones>`_ for your local time zone or a ``tzinfo``
  54. object with the local timezone information, under Unix and Windows.
  55. This module attempts to fix a glaring hole in the ``pytz`` and ``zoneinfo``
  56. modules, that there is no way to get the local timezone information, unless
  57. you know the zoneinfo name, and under several Linux distros that's hard or
  58. impossible to figure out.
  59. With ``tzlocal`` you only need to call ``get_localzone()`` and you will get a
  60. ``tzinfo`` object with the local time zone info. On some Unices you will
  61. still not get to know what the timezone name is, but you don't need that when
  62. you have the tzinfo file. However, if the timezone name is readily available
  63. it will be used.
  64. What it's not for
  65. -----------------
  66. It's not for converting the current time between UTC and your local time. There are
  67. other, simpler ways of doing this. This is if you need to know things like the name
  68. of the time zone, or if you need to be able to convert between your time zone and
  69. another time zone for times that are in the future or in the past.
  70. For current time conversions to and from UTC, look in the Python ``time`` module.
  71. Supported systems
  72. -----------------
  73. These are the systems that are in theory supported:
  74. * Windows 2000 and later
  75. * Any unix-like system with a ``/etc/localtime`` or ``/usr/local/etc/localtime``
  76. If you have one of the above systems and it does not work, it's a bug.
  77. Please report it.
  78. Please note that if you are getting a time zone called ``local``, this is not
  79. a bug, it's actually the main feature of ``tzlocal``, that even if your
  80. system does NOT have a configuration file with the zoneinfo name of your time
  81. zone, it will still work.
  82. You can also use ``tzlocal`` to get the name of your local timezone, but only
  83. if your system is configured to make that possible. ``tzlocal`` looks for the
  84. timezone name in ``/etc/timezone``, ``/var/db/zoneinfo``,
  85. ``/etc/sysconfig/clock`` and ``/etc/conf.d/clock``. If your
  86. ``/etc/localtime`` is a symlink it can also extract the name from that
  87. symlink.
  88. If you need the name of your local time zone, then please make sure your
  89. system is properly configured to allow that.
  90. If your unix system doesn't have a timezone configured, tzlocal will default
  91. to UTC.
  92. Notes on Docker
  93. ---------------
  94. It turns out that Docker images frequently have broken timezone setups.
  95. This usually results in a warning that the configuration is wrong, or that
  96. the timezone offset doesn't match the found timezone.
  97. The easiest way to fix that is to set a TZ variable in your docker setup
  98. to whatever timezone you want, which is usually the timezone your host
  99. computer has.
  100. Usage
  101. -----
  102. Load the local timezone:
  103. >>> from tzlocal import get_localzone
  104. >>> tz = get_localzone()
  105. >>> tz
  106. zoneinfo.ZoneInfo(key='Europe/Warsaw')
  107. Create a local datetime:
  108. >>> from datetime import datetime
  109. >>> dt = datetime(2015, 4, 10, 7, 22, tzinfo=tz)
  110. >>> dt
  111. datetime.datetime(2015, 4, 10, 7, 22, tzinfo=zoneinfo.ZoneInfo(key='Europe/Warsaw'))
  112. Lookup another timezone with ``zoneinfo``:
  113. >>> from zoneinfo import ZoneInfo
  114. >>> eastern = ZoneInfo('US/Eastern')
  115. Convert the datetime:
  116. >>> dt.astimezone(eastern)
  117. datetime.datetime(2015, 4, 10, 1, 22, tzinfo=zoneinfo.ZoneInfo(key='US/Eastern'))
  118. If you just want the name of the local timezone, use `get_localzone_name()`:
  119. >>> from tzlocal import get_localzone_name
  120. >>> get_localzone_name()
  121. "Europe/Warsaw"
  122. Please note that under Unix, `get_localzone_name()` may fail if there is no zone
  123. configured, where `get_localzone()` would generally succeed.
  124. Troubleshooting
  125. ---------------
  126. If you don't get the result you expect, try running it with debugging turned on.
  127. Start a python interpreter that has tzlocal installed, and run the following code::
  128. import logging
  129. logging.basicConfig(level="DEBUG")
  130. import tzlocal
  131. tzlocal.get_localzone()
  132. The output should look something like this, and this will tell you what
  133. configurations were found::
  134. DEBUG:root:/etc/timezone found, contents:
  135. Europe/Warsaw
  136. DEBUG:root:/etc/localtime found
  137. DEBUG:root:2 found:
  138. {'/etc/timezone': 'Europe/Warsaw', '/etc/localtime is a symlink to': 'Europe/Warsaw'}
  139. zoneinfo.ZoneInfo(key='Europe/Warsaw')
  140. Development
  141. -----------
  142. For ease of development, there is a Makefile that will help you with basic tasks,
  143. like creating a development environment with all the necessary tools (although
  144. you need a supported Python version installed first)::
  145. $ make devenv
  146. To run tests::
  147. $ make test
  148. Check the syntax::
  149. $ make check
  150. Maintainer
  151. ----------
  152. * Lennart Regebro, regebro@gmail.com
  153. Contributors
  154. ------------
  155. * Marc Van Olmen
  156. * Benjamen Meyer
  157. * Manuel Ebert
  158. * Xiaokun Zhu
  159. * Cameris
  160. * Edward Betts
  161. * McK KIM
  162. * Cris Ewing
  163. * Ayala Shachar
  164. * Lev Maximov
  165. * Jakub Wilk
  166. * John Quarles
  167. * Preston Landers
  168. * Victor Torres
  169. * Jean Jordaan
  170. * Zackary Welch
  171. * Mickaël Schoentgen
  172. * Gabriel Corona
  173. * Alex Grönholm
  174. * Julin S
  175. * Miroslav Šedivý
  176. * revansSZ
  177. * Sam Treweek
  178. * Peter Di Pasquale
  179. * Rongrong
  180. (Sorry if I forgot someone)
  181. License
  182. -------
  183. * MIT https://opensource.org/licenses/MIT