Helper function to determine if a timezone is ambiguous using python's dateutil module. Returns False if the timezone cannot detect ambiguity, or if there is no ambiguity, otherwise True. In order to detect ambiguous datetimes, the timezone must be built using ZoneInfo, or have an is_ambig
(dt: datetime, tz: tzinfo)
| 336 | |
| 337 | |
| 338 | def _is_ambiguous(dt: datetime, tz: tzinfo) -> bool: |
| 339 | """Helper function to determine if a timezone is ambiguous using python's dateutil module. |
| 340 | |
| 341 | Returns False if the timezone cannot detect ambiguity, or if there is no ambiguity, otherwise True. |
| 342 | |
| 343 | In order to detect ambiguous datetimes, the timezone must be built using ZoneInfo, or have an is_ambiguous |
| 344 | method. Previously, pytz timezones would throw an AmbiguousTimeError if the localized dt was ambiguous, |
| 345 | but now we need to specifically check for ambiguity with dateutil, as pytz is deprecated. |
| 346 | """ |
| 347 | |
| 348 | return _can_detect_ambiguous(tz) and dateutil_tz.datetime_ambiguous(dt) |
| 349 | |
| 350 | |
| 351 | def make_aware(dt: datetime, tz: tzinfo) -> datetime: |
no test coverage detected