Skip to content

Commit 24abdca

Browse files
committed
add timezone docs
1 parent 545b81d commit 24abdca

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

hypothesis-python/src/hypothesis/extra/dateutil.py

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
1818
You can use this strategy to make :func:`~hypothesis.strategies.datetimes`
1919
and :func:`~hypothesis.strategies.times` produce timezone-aware values.
20+
21+
.. tip::
22+
Consider using the stdlib :mod:`zoneinfo` module, via
23+
:func:`st.timezones() <hypothesis.strategies.timezones>`.
2024
"""
2125

2226
import datetime as dt

hypothesis-python/src/hypothesis/extra/pytz.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@
1515
1616
This module provides :pypi:`pytz` timezones.
1717
18-
You can use this strategy to make
19-
:py:func:`hypothesis.strategies.datetimes` and
20-
:py:func:`hypothesis.strategies.times` produce timezone-aware values.
18+
If you are unable to use the stdlib :mod:`zoneinfo` module, e.g. via the
19+
:func:`hypothesis.strategies.timezones` strategy, you can use this
20+
strategy with :py:func:`hypothesis.strategies.datetimes` and
21+
:py:func:`hypothesis.strategies.times` to produce timezone-aware values.
22+
23+
.. deprecated:: :mod:`zoneinfo` was added
24+
we intend to remove ``hypothesis.extra.pytz``, after libraries
25+
such as Pandas and Django complete their own migrations.
2126
"""
2227

2328
import datetime as dt
@@ -37,8 +42,12 @@ def timezones() -> st.SearchStrategy[dt.tzinfo]:
3742
"""Any timezone in the Olsen database, as a pytz tzinfo object.
3843
3944
This strategy minimises to UTC, or the smallest possible fixed
40-
offset, and is designed for use with
41-
:py:func:`hypothesis.strategies.datetimes`.
45+
offset, and is designed for use with :func:`hypothesis.strategies.datetimes`.
46+
47+
.. tip::
48+
Prefer the :func:`hypothesis.strategies.timezones` strategy, which uses
49+
the stdlib :mod:`zoneinfo` module and avoids `the many footguns in pytz
50+
<https://blog.ganssle.io/articles/2018/03/pytz-fastest-footgun.html>`__.
4251
"""
4352
all_timezones = [pytz.timezone(tz) for tz in pytz.all_timezones]
4453
# Some timezones have always had a constant offset from UTC. This makes

0 commit comments

Comments
 (0)