Skip to content
Closed
Changes from all commits
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
16 changes: 15 additions & 1 deletion Lib/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ def weekday(year, month, day):


def _validate_month(month):
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is needed. The code is small and pretty clear.

Validate that the month value is within the allowed range (1–12).

Raises:
TypeError: if month is not an integer
IllegalMonthError: if the month is outside the valid range
"""
if not isinstance(month, int):
raise TypeError(f"month must be int, not {type(month).__name__}")
if not 1 <= month <= 12:
raise IllegalMonthError(month)

Expand Down Expand Up @@ -832,7 +841,12 @@ def formatstring(cols, colwidth=_colwidth, spacing=_spacing):


def timegm(tuple):
"""Unrelated but handy function to calculate Unix timestamp from GMT."""
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to have a short description. The full description is in https://docs.python.org/3/library/calendar.html#calendar.timegm.

Convert a time tuple in UTC (GMT) to seconds since the Unix epoch.

This function is the inverse of time.gmtime() and does not apply
any timezone or daylight saving adjustments.
"""
year, month, day, hour, minute, second = tuple[:6]
days = datetime.date(year, month, 1).toordinal() - _EPOCH_ORD + day - 1
hours = days*24 + hour
Expand Down
Loading