mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-12-14 15:56:17 +00:00
Replace pytz with stdlib zoneinfo/timezone, Bump python to 3.10
* Timezone support comes with the standard lib since 3.9 * Bump to 3.10 because typing.TypeGuard
This commit is contained in:
committed by
Andreas
parent
6cf1215ba1
commit
12c9e4428e
@@ -1,21 +1,18 @@
|
||||
import datetime
|
||||
|
||||
import pytz
|
||||
import zoneinfo
|
||||
|
||||
|
||||
def ist_dst_wechsel(tag, timezone="Europe/Berlin"):
|
||||
def ist_dst_wechsel(tag: datetime.datetime, timezone="Europe/Berlin") -> bool:
|
||||
"""Checks if Daylight Saving Time (DST) starts or ends on a given day."""
|
||||
tz = pytz.timezone(timezone)
|
||||
tz = zoneinfo.ZoneInfo(timezone)
|
||||
# Get the current day and the next day
|
||||
current_day = datetime.datetime(tag.year, tag.month, tag.day)
|
||||
next_day = current_day + datetime.timedelta(days=1)
|
||||
|
||||
# Localize the days in the given timezone
|
||||
current_day_localized = tz.localize(current_day, is_dst=None)
|
||||
next_day_localized = tz.localize(next_day, is_dst=None)
|
||||
|
||||
# Check if the UTC offsets are different (indicating a DST change)
|
||||
dst_change = current_day_localized.dst() != next_day_localized.dst()
|
||||
dst_change = (
|
||||
current_day.replace(tzinfo=tz).dst() != next_day.replace(tzinfo=tz).dst()
|
||||
)
|
||||
|
||||
return dst_change
|
||||
|
||||
|
||||
Reference in New Issue
Block a user