2024-03-31 13:00:01 +02:00
|
|
|
import datetime
|
2024-10-07 22:38:14 +02:00
|
|
|
import zoneinfo
|
2024-10-03 11:05:44 +02:00
|
|
|
|
2024-03-31 13:00:01 +02:00
|
|
|
|
2024-11-16 21:52:51 +01:00
|
|
|
# currently unused
|
2024-10-07 22:38:14 +02:00
|
|
|
def ist_dst_wechsel(tag: datetime.datetime, timezone="Europe/Berlin") -> bool:
|
2024-09-20 13:04:52 +02:00
|
|
|
"""Checks if Daylight Saving Time (DST) starts or ends on a given day."""
|
2024-10-07 22:38:14 +02:00
|
|
|
tz = zoneinfo.ZoneInfo(timezone)
|
2024-09-20 13:04:52 +02:00
|
|
|
# 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)
|
2024-03-31 13:00:01 +02:00
|
|
|
|
2024-09-20 13:04:52 +02:00
|
|
|
# Check if the UTC offsets are different (indicating a DST change)
|
2024-10-10 15:00:32 +02:00
|
|
|
dst_change = current_day.replace(tzinfo=tz).dst() != next_day.replace(tzinfo=tz).dst()
|
2024-03-31 13:00:01 +02:00
|
|
|
|
2024-09-20 13:04:52 +02:00
|
|
|
return dst_change
|
2024-03-31 13:00:01 +02:00
|
|
|
|
2024-10-03 11:05:44 +02:00
|
|
|
|
2024-09-20 13:04:52 +02:00
|
|
|
# # Example usage
|
|
|
|
# start_date = datetime.datetime(2024, 3, 31) # Date of the DST change
|
|
|
|
# if ist_dst_wechsel(start_date):
|
2024-10-03 11:05:44 +02:00
|
|
|
# prediction_hours = 23 # Adjust to 23 hours for DST change days
|
2024-04-01 13:16:24 +02:00
|
|
|
# else:
|
2024-10-03 11:05:44 +02:00
|
|
|
# prediction_hours = 24 # Default value for days without DST change
|