8000 gh-112240: Add option to calendar module CLI to specify the weekday t… · python/cpython@2c089b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c089b0

Browse files
authored
gh-112240: Add option to calendar module CLI to specify the weekday to start each week (GH-112241)
1 parent 39c766b commit 2c089b0

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Doc/library/calendar.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,16 @@ The following options are accepted:
586586
or as an HTML document.
587587

588588

589+
.. option:: --first-weekday WEEKDAY, -f WEEKDAY
590+
591+
The weekday to start each week.
592+
Must be a number between 0 (Monday) and 6 (Sunday).
593+
Defaults to 0.
594+
595+
589596
.. option:: year
590597

591598
The year to print the calendar for.
592-
Must be a number between 1 and 9999.
593599
Defaults to the current year.
594600

595601

Lib/calendar.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,11 @@ def main(args=None):
734734
choices=("text", "html"),
735735
help="output type (text or html)"
736736
)
737+
parser.add_argument(
738+
"-f", "--first-weekday",
739+
type=int, default=0,
740+
help="weekday (0 is Monday, 6 is Sunday) to start each week (default 0)"
741+
)
737742
parser.add_argument(
738743
"year",
739744
nargs='?', type=int,
@@ -761,6 +766,7 @@ def main(args= 8000 None):
761766
cal = LocaleHTMLCalendar(locale=locale)
762767
else:
763768
cal = HTMLCalendar()
769+
cal.setfirstweekday(options.first_weekday)
764770
encoding = options.encoding
765771
if encoding is None:
766772
encoding = sys.getdefaultencoding()
@@ -775,6 +781,7 @@ def main(args=None):
775781
cal = LocaleTextCalendar(locale=locale)
776782
else:
777783
cal = TextCalendar()
784+
cal.setfirstweekday(options.first_weekday)
778785
optdict = dict(w=options.width, l=options.lines)
779786
if options.month is None:
780787
optdict["c"] = options.spacing
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add option to calendar module CLI to specify the weekday to start each week.
3556 2+
Patch by Steven Ward.

0 commit comments

Comments
 (0)
0