Handle timezone

This commit is contained in:
nemunaire 2022-08-12 12:48:39 +02:00
parent 560dd5f7a8
commit 9e15da095b
2 changed files with 11 additions and 5 deletions

View File

@ -158,8 +158,8 @@ class WeatherSunMoonModule:
import time
infos = {
"sunrise": datetime.fromtimestamp(thisdayweather["sunriseTime"], tz=timezone.utc).strftime("%X"),
"sunset": datetime.fromtimestamp(thisdayweather["sunsetTime"], tz=timezone.utc).strftime("%X"),
"sunrise": WeatherAPI().read_timestamp(thisdayweather["sunriseTime"]).strftime("%X"),
"sunset": WeatherAPI().read_timestamp(thisdayweather["sunsetTime"]).strftime("%X"),
"4": "",
}
@ -219,7 +219,7 @@ class WeatherTemperatureModule:
hours_weather = WeatherAPI().get_hourly()
line_chart.x_labels = [datetime.fromtimestamp(d["time"], tz=timezone.utc).strftime("%Hh") if datetime.fromtimestamp(d["time"]).hour % 2 == 0 else "" for d in hours_weather["data"][:self.limit_futur]]
line_chart.x_labels = [WeatherAPI().read_timestamp(d["time"]).strftime("%Hh") if datetime.fromtimestamp(d["time"]).hour % 2 == 0 else "" for d in hours_weather["data"][:self.limit_futur]]
line_chart.add('Températures', [d["temperature"] for d in hours_weather["data"][:self.limit_futur]], show_dots=False)
@ -330,8 +330,8 @@ class WeatherAlertsModule:
alert["title"],
fill="white", anchor="lt", font=fnt_B
)
startTime = datetime.fromtimestamp(alert["time"], tz=timezone.utc)
endTime = datetime.fromtimestamp(alert["expires"], tz=timezone.utc)
startTime = WeatherAPI().read_timestamp(alert["time"])
endTime = WeatherAPI().read_timestamp(alert["expires"])
# Show alert timing if under a day
if startTime.hour != endTime.hour:
draw.text(

View File

@ -151,6 +151,12 @@ class DarkSkyAPI:
def get_alerts(self, *args, **kwargs):
return self.get_weather(*args, **kwargs)["alerts"]
def read_timestamp(self, timestamp, *args, **kwargs):
wth = self.get_weather(*args, **kwargs)
tz = timezone(timedelta(hours=wth["offset"]), wth["timezone"])
return datetime.fromtimestamp(timestamp, tz=tz)
WeatherAPI = DarkSkyAPI