EOS/src/akkudoktoreos/class_sommerzeit.py
Dominique Lasserre e936aaf134
visualize: Keep shape of plots the same on dst change Closes #185 (#203)
* Currently prediction hours are relative from current hour and don't
   adjust on daylight saving change.
 * ist_dst_wechsel now unused.
2024-11-16 21:52:51 +01:00

25 lines
875 B
Python

import datetime
import zoneinfo
# currently unused
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 = 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)
# Check if the UTC offsets are different (indicating a DST change)
dst_change = current_day.replace(tzinfo=tz).dst() != next_day.replace(tzinfo=tz).dst()
return dst_change
# # Example usage
# start_date = datetime.datetime(2024, 3, 31) # Date of the DST change
# if ist_dst_wechsel(start_date):
# prediction_hours = 23 # Adjust to 23 hours for DST change days
# else:
# prediction_hours = 24 # Default value for days without DST change