From 58b7a19259a0212be6679e7238bea882a8b5c9ee Mon Sep 17 00:00:00 2001 From: null8626 Date: Sat, 19 Oct 2024 11:26:07 +0700 Subject: [PATCH] refactor: use fromisoformat instead of strptime --- python_weather/forecast.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python_weather/forecast.py b/python_weather/forecast.py index 7f1eb7a..5ac1e46 100644 --- a/python_weather/forecast.py +++ b/python_weather/forecast.py @@ -121,7 +121,7 @@ def __init__(self, json: dict, unit: _Unit, locale: Locale): self.chances_of_thunder = int(json['chanceofthunder']) self.chances_of_windy = int(json['chanceofwindy']) self.cloud_cover = int(json['cloudcover']) - self.time = time() if len(t) < 3 else datetime.strptime(t, '%H%M').time() + self.time = time() if len(t) < 3 else time.fromisoformat(t) self.dew_point = int(json[f'DewPoint{unit.temperature}']) self.heat_index = HeatIndex._new( celcius_index, @@ -201,7 +201,7 @@ def __init__(self, json: dict, unit: _Unit, locale: Locale): self.moonset = __class__.__parse_time(astronomy['moonset']) self.sunrise = __class__.__parse_time(astronomy['sunrise']) self.sunset = __class__.__parse_time(astronomy['sunset']) - self.date = datetime.strptime(json['date'], '%Y-%m-%d').date() + self.date = date.fromisoformat(json['date']) self.sunlight = float(json['sunHour']) self.lowest_temperature = int(json[f'mintemp{unit.temperature}']) self.highest_temperature = int(json[f'maxtemp{unit.temperature}'])