diff --git a/aemet_opendata/const.py b/aemet_opendata/const.py index 49df5fc..6b9ac4a 100644 --- a/aemet_opendata/const.py +++ b/aemet_opendata/const.py @@ -103,7 +103,8 @@ AOD_TEMP_FEELING: Final[str] = "temperature-feeling" AOD_TEMP_MAX: Final[str] = "temperature-max" AOD_TEMP_MIN: Final[str] = "temperature-min" -AOD_TIMESTAMP: Final[str] = "timestamp" +AOD_TIMESTAMP_LOCAL: Final[str] = "timestamp-local" +AOD_TIMESTAMP_UTC: Final[str] = "timestamp-utc" AOD_TIMEZONE: Final[str] = "timezone" AOD_TOWN: Final[str] = "town" AOD_UV_INDEX: Final[str] = "uv-index" diff --git a/aemet_opendata/forecast.py b/aemet_opendata/forecast.py index 0368056..3d59ca6 100644 --- a/aemet_opendata/forecast.py +++ b/aemet_opendata/forecast.py @@ -1,6 +1,6 @@ """AEMET OpenData Forecast.""" -from datetime import datetime +from datetime import datetime, timezone from typing import Any, Final from .const import ( @@ -53,7 +53,8 @@ AOD_TEMP, AOD_TEMP_MAX, AOD_TEMP_MIN, - AOD_TIMESTAMP, + AOD_TIMESTAMP_LOCAL, + AOD_TIMESTAMP_UTC, AOD_UV_INDEX, AOD_WIND_DIRECTION, AOD_WIND_SPEED, @@ -311,10 +312,14 @@ def get_temp_min(self) -> int: """Return Town daily forecast minimum temperature.""" return self.temp_min - def get_timestamp(self) -> str: - """Return Town daily forecast timestamp.""" + def get_timestamp_local(self) -> str: + """Return Town daily forecast local timestamp.""" return self._datetime.isoformat() + def get_timestamp_utc(self) -> str: + """Return Town daily forecast UTC timestamp.""" + return self._datetime.astimezone(timezone.utc).isoformat() + def get_uv_index(self) -> int | None: """Return Town daily forecast UV index.""" return self.uv_index @@ -338,7 +343,8 @@ def data(self) -> dict[str, Any]: AOD_PRECIPITATION_PROBABILITY: self.get_precipitation_prob(), AOD_TEMP_MAX: self.get_temp_max(), AOD_TEMP_MIN: self.get_temp_min(), - AOD_TIMESTAMP: self.get_timestamp(), + AOD_TIMESTAMP_LOCAL: self.get_timestamp_local(), + AOD_TIMESTAMP_UTC: self.get_timestamp_utc(), AOD_UV_INDEX: self.get_uv_index(), AOD_WIND_DIRECTION: self.get_wind_direction(), AOD_WIND_SPEED: self.get_wind_speed(), @@ -549,10 +555,14 @@ def get_temp(self) -> int | None: """Return Town hourly forecast temperature.""" return self.temp - def get_timestamp(self) -> str: - """Return Town hourly forecast timestamp.""" + def get_timestamp_local(self) -> str: + """Return Town hourly forecast local timestamp.""" return self._datetime.isoformat() + def get_timestamp_utc(self) -> str: + """Return Town hourly forecast UTC timestamp.""" + return self._datetime.astimezone(timezone.utc).isoformat() + def get_wind_direction(self) -> float | None: """Return Town hourly forecast wind direction.""" return self.wind_direction @@ -581,7 +591,8 @@ def data(self) -> dict[str, Any]: AOD_SUNRISE: self.get_sunrise(), AOD_SUNSET: self.get_sunset(), AOD_TEMP: self.get_temp(), - AOD_TIMESTAMP: self.get_timestamp(), + AOD_TIMESTAMP_LOCAL: self.get_timestamp_local(), + AOD_TIMESTAMP_UTC: self.get_timestamp_utc(), AOD_WIND_DIRECTION: self.get_wind_direction(), AOD_WIND_SPEED: self.get_wind_speed(), AOD_WIND_SPEED_MAX: self.get_wind_speed_max(), diff --git a/aemet_opendata/interface.py b/aemet_opendata/interface.py index 6ed5d4e..985fb3b 100644 --- a/aemet_opendata/interface.py +++ b/aemet_opendata/interface.py @@ -33,7 +33,7 @@ AOD_STATION, AOD_STORM_PROBABILITY, AOD_TEMP, - AOD_TIMESTAMP, + AOD_TIMESTAMP_UTC, AOD_TOWN, AOD_UV_INDEX, AOD_WEATHER, @@ -233,7 +233,7 @@ def data(self) -> dict[str, Any]: if weather is not None: data[AOD_WEATHER] = weather - data[AOD_TIMESTAMP] = get_current_datetime().isoformat() + data[AOD_TIMESTAMP_UTC] = get_current_datetime().isoformat() return data diff --git a/aemet_opendata/station.py b/aemet_opendata/station.py index 3f838fc..6c02b9c 100644 --- a/aemet_opendata/station.py +++ b/aemet_opendata/station.py @@ -36,7 +36,7 @@ AOD_TEMP, AOD_TEMP_MAX, AOD_TEMP_MIN, - AOD_TIMESTAMP, + AOD_TIMESTAMP_UTC, AOD_TIMEZONE, AOD_WIND_DIRECTION, AOD_WIND_SPEED, @@ -146,8 +146,8 @@ def get_temp_min(self) -> float | None: """Return Station minimum temperature.""" return self.temp_min - def get_timestamp(self) -> str: - """Return Station timestamp.""" + def get_timestamp_utc(self) -> str: + """Return Station UTC timestamp.""" return self._datetime.isoformat() def get_timezone(self) -> ZoneInfo: @@ -229,7 +229,7 @@ def data(self) -> dict[str, Any]: AOD_ID: self.get_id(), AOD_NAME: self.get_name(), AOD_OUTDATED: self.get_outdated(), - AOD_TIMESTAMP: self.get_timestamp(), + AOD_TIMESTAMP_UTC: self.get_timestamp_utc(), AOD_TIMEZONE: self.get_timezone(), } diff --git a/aemet_opendata/town.py b/aemet_opendata/town.py index 75a7fdd..5692c6c 100644 --- a/aemet_opendata/town.py +++ b/aemet_opendata/town.py @@ -1,6 +1,6 @@ """AEMET OpenData Town.""" -from datetime import datetime +from datetime import datetime, timezone import logging from typing import Any from zoneinfo import ZoneInfo @@ -37,7 +37,8 @@ AOD_SNOW_PROBABILITY, AOD_STORM_PROBABILITY, AOD_TEMP, - AOD_TIMESTAMP, + AOD_TIMESTAMP_LOCAL, + AOD_TIMESTAMP_UTC, AOD_TIMEZONE, AOD_UV_INDEX, AOD_WIND_DIRECTION, @@ -96,10 +97,14 @@ def get_current_forecast(self) -> DailyForecastValue | None: return leg_forecast return None - def get_timestamp(self) -> str: + def get_timestamp_local(self) -> str: """Return Town daily forecast timestamp.""" return self._datetime.isoformat() + def get_timestamp_utc(self) -> str: + """Return Town daily forecast timestamp.""" + return self._datetime.astimezone(timezone.utc).isoformat() + def get_timezone(self) -> ZoneInfo: """Return Town daily forecast timezone.""" return self.zoneinfo @@ -108,7 +113,8 @@ def data(self) -> dict[str, Any]: """Return Town daily forecast data.""" data: dict[str, Any] = { AOD_FORECAST: [], - AOD_TIMESTAMP: self.get_timestamp(), + AOD_TIMESTAMP_LOCAL: self.get_timestamp_local(), + AOD_TIMESTAMP_UTC: self.get_timestamp_utc(), AOD_TIMEZONE: self.get_timezone(), } @@ -189,6 +195,14 @@ def get_timestamp(self) -> str: """Return Town hourly forecast timestamp.""" return self._datetime.isoformat() + def get_timestamp_local(self) -> str: + """Return Town daily forecast timestamp.""" + return self._datetime.isoformat() + + def get_timestamp_utc(self) -> str: + """Return Town daily forecast timestamp.""" + return self._datetime.astimezone(timezone.utc).isoformat() + def get_timezone(self) -> ZoneInfo: """Return Town hourly forecast timezone.""" return self.zoneinfo @@ -197,7 +211,8 @@ def data(self) -> dict[str, Any]: """Return Town hourly forecast data.""" data: dict[str, Any] = { AOD_FORECAST: [], - AOD_TIMESTAMP: self.get_timestamp(), + AOD_TIMESTAMP_LOCAL: self.get_timestamp_local(), + AOD_TIMESTAMP_UTC: self.get_timestamp_utc(), AOD_TIMEZONE: self.get_timezone(), }