@@ -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-
377262def 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.
0 commit comments