Skip to content

Commit a14dd87

Browse files
committed
pythongh-103822: change return value to enums for days and month API in
calendar module
1 parent d862799 commit a14dd87

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Lib/calendar.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ class Day(IntEnum):
7070
SUNDAY = 6
7171

7272

73+
def _get_enum_attribute(value, enum_type):
74+
"""Returns the value of the specified attribute of a Day or Month Enum object based on its integer value."""
75+
if enum_type == "day":
76+
return Day(value)
77+
else:
78+
return Month(value)
79+
7380

7481
# Number of days per month (except for February in leap years)
7582
mdays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
@@ -143,7 +150,7 @@ def weekday(year, month, day):
143150
"""Return weekday (0-6 ~ Mon-Sun) for year, month (1-12), day (1-31)."""
144151
if not datetime.MINYEAR <= year <= datetime.MAXYEAR:
145152
year = 2000 + year % 400
146-
return datetime.date(year, month, day).weekday()
153+
return _get_enum_attribute(datetime.date(year, month, day).weekday(),'day')
147154

148155

149156
def monthrange(year, month):

0 commit comments

Comments
 (0)