From c34f63de06d365c4da75cb3a2f1a573843a5ead1 Mon Sep 17 00:00:00 2001 From: Zhi Heng Date: Mon, 5 Aug 2024 06:43:59 +0800 Subject: [PATCH] Make ShiyuDefense begin_time and end_time Optional (#217) --- genshin/models/zzz/chronicle/challenge.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/genshin/models/zzz/chronicle/challenge.py b/genshin/models/zzz/chronicle/challenge.py index e6f60b62..700ff379 100644 --- a/genshin/models/zzz/chronicle/challenge.py +++ b/genshin/models/zzz/chronicle/challenge.py @@ -114,8 +114,8 @@ class ShiyuDefense(APIModel): """ZZZ Shiyu Defense model.""" schedule_id: int - begin_time: datetime.datetime = Aliased("hadal_begin_time") - end_time: datetime.datetime = Aliased("hadal_end_time") + begin_time: typing.Optional[datetime.datetime] = Aliased("hadal_begin_time") + end_time: typing.Optional[datetime.datetime] = Aliased("hadal_end_time") has_data: bool ratings: typing.Mapping[typing.Literal["S", "A", "B"], int] = Aliased("rating_list") floors: typing.List[ShiyuDefenseFloor] = Aliased("all_floor_detail") @@ -133,8 +133,10 @@ def __convert_ratings( @pydantic.validator("begin_time", "end_time", pre=True) @classmethod def __add_timezone( - cls, v: typing.Dict[typing.Literal["year", "month", "day", "hour", "minute", "second"], int] - ) -> datetime.datetime: - return datetime.datetime( - v["year"], v["month"], v["day"], v["hour"], v["minute"], v["second"], tzinfo=CN_TIMEZONE - ) + cls, v: typing.Optional[typing.Dict[typing.Literal["year", "month", "day", "hour", "minute", "second"], int]] + ) -> typing.Optional[datetime.datetime]: + if v is not None: + return datetime.datetime( + v["year"], v["month"], v["day"], v["hour"], v["minute"], v["second"], tzinfo=CN_TIMEZONE + ) + return None