Update datetime.py

This commit is contained in:
blueloveTH 2023-10-30 23:58:43 +08:00
parent 905defb534
commit 4b00846861

View File

@ -35,7 +35,7 @@ class timedelta:
class date: class date:
def __init__(self, year: int, month: int = None, day: int = None): def __init__(self, year: int, month: int, day: int):
self.year = year self.year = year
self.month = month self.month = month
self.day = day self.day = day
@ -78,16 +78,16 @@ class date:
class datetime(date): class datetime(date):
def __init__(self, year: int, month: int = None, day: int = None, hour: int = None, minute: int = None, second: int = None): def __init__(self, year: int, month: int, day: int, hour: int, minute: int, second: int):
super().__init__(year, month, day) super().__init__(year, month, day)
# Validate and set hour, minute, and second # Validate and set hour, minute, and second
if hour is not None and not 0 <= hour <= 23: if not 0 <= hour <= 23:
raise ValueError("Hour must be between 0 and 23") raise ValueError("Hour must be between 0 and 23")
self.hour = hour self.hour = hour
if minute is not None and not 0 <= minute <= 59: if not 0 <= minute <= 59:
raise ValueError("Minute must be between 0 and 59") raise ValueError("Minute must be between 0 and 59")
self.minute = minute self.minute = minute
if second is not None and not 0 <= second <= 59: if not 0 <= second <= 59:
raise ValueError("Second must be between 0 and 59") raise ValueError("Second must be between 0 and 59")
self.second = second self.second = second