METADATA 7.6 KB

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