Skip to content

Commit cebe392

Browse files
committed
Finally remove get_next_timezone_transition
1 parent 2c1875e commit cebe392

File tree

3 files changed

+1
-139
lines changed

3 files changed

+1
-139
lines changed

babel/dates.py

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -259,121 +259,6 @@ def get_timezone(zone: str | datetime.tzinfo | None = None) -> datetime.tzinfo:
259259
raise LookupError(f"Unknown timezone {zone}") from exc
260260

261261

262-
def get_next_timezone_transition(zone: datetime.tzinfo | None = None, dt: _Instant = None) -> TimezoneTransition:
263-
"""Given a timezone it will return a :class:`TimezoneTransition` object
264-
that holds the information about the next timezone transition that's going
265-
to happen. For instance this can be used to detect when the next DST
266-
change is going to happen and how it looks like.
267-
268-
The transition is calculated relative to the given datetime object. The
269-
next transition that follows the date is used. If a transition cannot
270-
be found the return value will be `None`.
271-
272-
Transition information can only be provided for timezones returned by
273-
the :func:`get_timezone` function.
274-
275-
This function is pending deprecation with no replacement planned in the
276-
Babel library.
277-
278-
:param zone: the timezone for which the transition should be looked up.
279-
If not provided the local timezone is used.
280-
:param dt: the date after which the next transition should be found.
281-
If not given the current time is assumed.
282-
"""
283-
warnings.warn(
284-
"get_next_timezone_transition() is deprecated and will be "
285-
"removed in the next version of Babel. "
286-
"Please see https://github.com/python-babel/babel/issues/716 "
287-
"for discussion.",
288-
category=DeprecationWarning,
289-
)
290-
zone = get_timezone(zone)
291-
dt = _get_datetime(dt).replace(tzinfo=None)
292-
293-
if not hasattr(zone, '_utc_transition_times'):
294-
raise TypeError('Given timezone does not have UTC transition '
295-
'times. This can happen because the operating '
296-
'system fallback local timezone is used or a '
297-
'custom timezone object')
298-
299-
try:
300-
idx = max(0, bisect_right(zone._utc_transition_times, dt))
301-
old_trans = zone._transition_info[idx - 1]
302-
new_trans = zone._transition_info[idx]
303-
old_tz = zone._tzinfos[old_trans]
304-
new_tz = zone._tzinfos[new_trans]
305-
except (LookupError, ValueError):
306-
return None
307-
308-
return TimezoneTransition(
309-
activates=zone._utc_transition_times[idx],
310-
from_tzinfo=old_tz,
311-
to_tzinfo=new_tz,
312-
reference_date=dt
313-
)
314-
315-
316-
class TimezoneTransition:
317-
"""A helper object that represents the return value from
318-
:func:`get_next_timezone_transition`.
319-
320-
This class is pending deprecation with no replacement planned in the
321-
Babel library.
322-
323-
:field activates:
324-
The time of the activation of the timezone transition in UTC.
325-
:field from_tzinfo:
326-
The timezone from where the transition starts.
327-
:field to_tzinfo:
328-
The timezone for after the transition.
329-
:field reference_date:
330-
The reference date that was provided. This is the `dt` parameter
331-
to the :func:`get_next_timezone_transition`.
332-
"""
333-
334-
def __init__(
335-
self,
336-
activates: datetime.datetime,
337-
from_tzinfo: datetime.tzinfo,
338-
to_tzinfo: datetime.tzinfo,
339-
reference_date: datetime.datetime | None = None,
340-
) -> None:
341-
warnings.warn(
342-
"TimezoneTransition is deprecated and will be "
343-
"removed in the next version of Babel. "
344-
"Please see https://github.com/python-babel/babel/issues/716 "
345-
"for discussion.",
346-
category=DeprecationWarning,
347-
)
348-
self.activates = activates
349-
self.from_tzinfo = from_tzinfo
350-
self.to_tzinfo = to_tzinfo
351-
self.reference_date = reference_date
352-
353-
@property
354-
def from_tz(self) -> str:
355-
"""The name of the timezone before the transition."""
356-
return self.from_tzinfo._tzname
357-
358-
@property
359-
def to_tz(self) -> str:
360-
"""The name of the timezone after the transition."""
361-
return self.to_tzinfo._tzname
362-
363-
@property
364-
def from_offset(self) -> int:
365-
"""The UTC offset in seconds before the transition."""
366-
return int(self.from_tzinfo._utcoffset.total_seconds())
367-
368-
@property
369-
def to_offset(self) -> int:
370-
"""The UTC offset in seconds after the transition."""
371-
return int(self.to_tzinfo._utcoffset.total_seconds())
372-
373-
def __repr__(self) -> str:
374-
return f"<TimezoneTransition {self.from_tz} -> {self.to_tz} ({self.activates})>"
375-
376-
377262
def get_period_names(width: Literal['abbreviated', 'narrow', 'wide'] = 'wide',
378263
context: _Context = 'stand-alone', locale: Locale | str | None = LC_TIME) -> LocaleDataDict:
379264
"""Return the names for day periods (AM/PM) used by the locale.

docs/api/dates.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ Timezone Functionality
3232

3333
.. autofunction:: get_timezone_name
3434

35-
.. autofunction:: get_next_timezone_transition
36-
3735
.. data:: UTC
3836

3937
A timezone object for UTC.

docs/dates.rst

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -308,28 +308,7 @@ applied to ``format_time``, but because the actual date is unknown in that
308308
case, the current day is assumed to determine whether DST or standard time
309309
should be used.
310310

311-
For many timezones it's also possible to ask for the next timezone
312-
transition. This for instance is useful to answer the question “when do I
313-
have to move the clock forward next”:
314-
315-
.. warning:: ``get_next_timezone_transition`` is deprecated and will be removed
316-
in the next version of Babel
317-
318-
.. code-block:: pycon
319-
320-
>>> t = get_next_timezone_transition('Europe/Vienna', datetime(2011, 3, 2))
321-
>>> t
322-
<TimezoneTransition CET -> CEST (2011-03-27 01:00:00)>
323-
>>> t.from_offset
324-
3600.0
325-
>>> t.to_offset
326-
7200.0
327-
>>> t.from_tz
328-
'CET'
329-
>>> t.to_tz
330-
'CEST'
331-
332-
Lastly Babel also provides support for working with the local timezone of
311+
Babel also provides support for working with the local timezone of
333312
your operating system. It's provided through the ``LOCALTZ`` constant:
334313

335314
.. code-block:: pycon

0 commit comments

Comments
 (0)