]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-112240: Add option to calendar module CLI to specify the weekday to start each...
authorSteven Ward <planet36@users.noreply.github.com>
Mon, 29 Jan 2024 16:58:21 +0000 (11:58 -0500)
committerGitHub <noreply@github.com>
Mon, 29 Jan 2024 16:58:21 +0000 (16:58 +0000)
Doc/library/calendar.rst
Lib/calendar.py
Misc/NEWS.d/next/Library/2023-11-18-16-30-21.gh-issue-112240.YXS0tj.rst [new file with mode: 0644]

index 6586f539a8da4fca0a6a88054dd3de70a0c66f4c..c4dcf5641d60663af82f93703a544d23a051db89 100644 (file)
@@ -586,10 +586,16 @@ The following options are accepted:
    or as an HTML document.
 
 
+.. option:: --first-weekday WEEKDAY, -f WEEKDAY
+
+   The weekday to start each week.
+   Must be a number between 0 (Monday) and 6 (Sunday).
+   Defaults to 0.
+
+
 .. option:: year
 
    The year to print the calendar for.
-   Must be a number between 1 and 9999.
    Defaults to the current year.
 
 
index 3c79540f986b63c8eb326aea4a60f19eb5f5a656..833ce331b14a0ccdf07986ac6ba0903e323deeb2 100644 (file)
@@ -734,6 +734,11 @@ def main(args=None):
         choices=("text", "html"),
         help="output type (text or html)"
     )
+    parser.add_argument(
+        "-f", "--first-weekday",
+        type=int, default=0,
+        help="weekday (0 is Monday, 6 is Sunday) to start each week (default 0)"
+    )
     parser.add_argument(
         "year",
         nargs='?', type=int,
@@ -761,6 +766,7 @@ def main(args=None):
             cal = LocaleHTMLCalendar(locale=locale)
         else:
             cal = HTMLCalendar()
+        cal.setfirstweekday(options.first_weekday)
         encoding = options.encoding
         if encoding is None:
             encoding = sys.getdefaultencoding()
@@ -775,6 +781,7 @@ def main(args=None):
             cal = LocaleTextCalendar(locale=locale)
         else:
             cal = TextCalendar()
+        cal.setfirstweekday(options.first_weekday)
         optdict = dict(w=options.width, l=options.lines)
         if options.month is None:
             optdict["c"] = options.spacing
diff --git a/Misc/NEWS.d/next/Library/2023-11-18-16-30-21.gh-issue-112240.YXS0tj.rst b/Misc/NEWS.d/next/Library/2023-11-18-16-30-21.gh-issue-112240.YXS0tj.rst
new file mode 100644 (file)
index 0000000..686f031
--- /dev/null
@@ -0,0 +1,2 @@
+Add option to calendar module CLI to specify the weekday to start each week.
+Patch by Steven Ward.