GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-103636: add enums for days and months in calendar module by Agent-Hellboy · Pull Request #103642 · python/cpython

gh-103636: add enums for days and months in calendar module #103642

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.

Sign up for GitHub

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

Merged
ethanfurman merged 7 commits into python:main from Agent-Hellboy:fix-issue-103636
Apr 25, 2023

Uh oh!

There was an error while loading. Please reload this page.

Merged

gh-103636: add enums for days and months in calendar module #103642

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
7 commits
Select commit Hold shift + click to select a range
e0427ba
gh-103636: Convert Calander consts to enum and add consts for months
Agent-Hellboy Apr 20, 2023
41d42f1
📜🤖 Added by blurb_it.
blurb-it[bot] Apr 21, 2023
3aac302
fix spelling mistake and modify news entry
blurb-it[bot] Apr 21, 2023
ec8ee98
Merge branch 'fix-issue-103636' of https://github.com/Agent-Hellboy/c…
Agent-Hellboy Apr 22, 2023
fb66466
Merge branch 'main' into fix-issue-103636
ambv Apr 25, 2023
ca97985
Remove January and February Constants
Agent-Hellboy Apr 25, 2023
a2b14db
Revert accidental removal of a comment
Agent-Hellboy Apr 25, 2023
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

60 changes: 39 additions & 21 deletions 60 Lib/calendar.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import sys
import datetime
from enum import IntEnum, global_enum
import locale as _locale
from itertools import repeat

Expand All @@ -16,6 +17,9 @@
"timegm", "month_name", "month_abbr", "day_name", "day_abbr",
"Calendar", "TextCalendar", "HTMLCalendar", "LocaleTextCalendar",
"LocaleHTMLCalendar", "weekheader",
"Day", "Month", "JANUARY", "FEBRUARY", "MARCH",
"APRIL", "MAY", "JUNE", "JULY",
"AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER",
"MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY",
"SATURDAY", "SUNDAY"]

Expand All @@ -37,9 +41,35 @@ def __str__(self):
return "bad weekday number %r; must be 0 (Monday) to 6 (Sunday)" % self.weekday


# Constants for months referenced later
January = 1
February = 2
# Constants for months
@global_enum
class Month(IntEnum):
JANUARY = 1
FEBRUARY = 2
MARCH = 3
APRIL = 4
MAY = 5
JUNE = 6
JULY = 7
AUGUST = 8
SEPTEMBER = 9
OCTOBER = 10
NOVEMBER = 11
DECEMBER = 12


# Constants for days
@global_enum
class Day(IntEnum):
MONDAY = 0
TUESDAY = 1
WEDNESDAY = 2
THURSDAY = 3
FRIDAY = 4
SATURDAY = 5
SUNDAY = 6



Comment thread
Agent-Hellboy marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

# 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 @@ -95,9 +125,6 @@ def __len__(self):
month_name = _localized_month('%B')
month_abbr = _localized_month('%b')

# Constants for weekdays
(MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY) = range(7)


def isleap(year):
"""Return True for leap years, False for non-leap years."""
Expand Down Expand Up @@ -125,12 +152,12 @@ def monthrange(year, month):
if not 1 <= month <= 12:
raise IllegalMonthError(month)
day1 = weekday(year, month, 1)
ndays = mdays[month] + (month == February and isleap(year))
ndays = mdays[month] + (month == FEBRUARY and isleap(year))
return day1, ndays


def _monthlen(year, month):
return mdays[month] + (month == February and isleap(year))
return mdays[month] + (month == FEBRUARY and isleap(year))


def _prevmonth(year, month):
Expand Down Expand Up @@ -260,10 +287,7 @@ def yeardatescalendar(self, year, width=3):
Each month contains between 4 and 6 weeks and each week contains 1-7
days. Days are datetime.date objects.
"""
months = [
self.monthdatescalendar(year, i)
for i in range(January, January+12)
]
months = [self.monthdatescalendar(year, m) for m in Month]
return [months[i:i+width] for i in range(0, len(months), width) ]

def yeardays2calendar(self, year, width=3):
Expand All @@ -273,10 +297,7 @@ def yeardays2calendar(self, year, width=3):
(day number, weekday number) tuples. Day numbers outside this month are
zero.
"""
months = [
self.monthdays2calendar(year, i)
for i in range(January, January+12)
]
months = [self.monthdays2calendar(year, m) for m in Month]
return [months[i:i+width] for i in range(0, len(months), width) ]

def yeardayscalendar(self, year, width=3):
Expand All @@ -285,10 +306,7 @@ def yeardayscalendar(self, year, width=3):
yeardatescalendar()). Entries in the week lists are day numbers.
Day numbers outside this month are zero.
"""
months = [
self.monthdayscalendar(year, i)
for i in range(January, January+12)
]
months = [self.monthdayscalendar(year, m) for m in Month]
return [months[i:i+width] for i in range(0, len(months), width) ]


Expand Down Expand Up @@ -509,7 +527,7 @@ def formatyear(self, theyear, width=3):
a('\n')
a('<tr><th colspan="%d" class="%s">%s</th></tr>' % (
width, self.cssclass_year_head, theyear))
for i in range(January, January+12, width):
for i in range(JANUARY, JANUARY+12, width):
Comment thread
Agent-Hellboy marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

# months in this row
months = range(i, min(i+width, 13))
a('<tr>')
Expand Down
1 change: 1 addition & 0 deletions 1 Misc/NEWS.d/next/Library/2023-04-21-10-25-39.gh-issue-103636.YK6NEa.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added Enum for months and days in the calendar module.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.