mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-08-25 06:52:23 +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
|
||||
|
||||
|
@@ -1,20 +1,12 @@
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime, timedelta
|
||||
import zoneinfo
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
import numpy as np
|
||||
import pytz
|
||||
import requests
|
||||
|
||||
# Example: Converting a UTC timestamp to local time
|
||||
utc_time = datetime.strptime("2024-03-28T01:00:00.000Z", "%Y-%m-%dT%H:%M:%S.%fZ")
|
||||
utc_time = utc_time.replace(tzinfo=pytz.utc)
|
||||
|
||||
# Replace 'Europe/Berlin' with your own timezone
|
||||
local_time = utc_time.astimezone(pytz.timezone("Europe/Berlin"))
|
||||
print(local_time)
|
||||
|
||||
|
||||
def repeat_to_shape(array, target_shape):
|
||||
# Check if the array fits the target shape
|
||||
@@ -116,13 +108,13 @@ class HourlyElectricityPriceForecast:
|
||||
print(start_date_str)
|
||||
print(end_date_str)
|
||||
start_date_utc = datetime.strptime(start_date_str, "%Y-%m-%d").replace(
|
||||
tzinfo=pytz.utc
|
||||
tzinfo=timezone.utc
|
||||
)
|
||||
end_date_utc = datetime.strptime(end_date_str, "%Y-%m-%d").replace(
|
||||
tzinfo=pytz.utc
|
||||
tzinfo=timezone.utc
|
||||
)
|
||||
start_date = start_date_utc.astimezone(pytz.timezone("Europe/Berlin"))
|
||||
end_date = end_date_utc.astimezone(pytz.timezone("Europe/Berlin"))
|
||||
start_date = start_date_utc.astimezone(zoneinfo.ZoneInfo("Europe/Berlin"))
|
||||
end_date = end_date_utc.astimezone(zoneinfo.ZoneInfo("Europe/Berlin"))
|
||||
|
||||
price_list = []
|
||||
|
||||
|
Reference in New Issue
Block a user