Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-103822: change return value to enum for day and month APIs #103827

Merged
merged 3 commits into from
May 2, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Lib/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ class Day(IntEnum):
SUNDAY = 6


def _get_enum_attribute(value, enum_type):
Agent-Hellboy marked this conversation as resolved.
Show resolved Hide resolved
"""Returns the value of the specified attribute of a Day or Month Enum object based on its integer value."""
if enum_type == "day":
return Day(value)
else:
return Month(value)


# Number of days per month (except for February in leap years)
mdays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
Expand Down Expand Up @@ -143,7 +150,7 @@ def weekday(year, month, day):
"""Return weekday (0-6 ~ Mon-Sun) for year, month (1-12), day (1-31)."""
if not datetime.MINYEAR <= year <= datetime.MAXYEAR:
year = 2000 + year % 400
return datetime.date(year, month, day).weekday()
return _get_enum_attribute(datetime.date(year, month, day).weekday(),'day')
Agent-Hellboy marked this conversation as resolved.
Show resolved Hide resolved


def monthrange(year, month):
Expand Down