]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
cal: fix first week calculation
authorJ William Piggott <elseifthen@gmx.com>
Mon, 22 Jan 2018 12:03:27 +0000 (07:03 -0500)
committerKarel Zak <kzak@redhat.com>
Mon, 22 Jan 2018 13:16:57 +0000 (14:16 +0100)
Commit efafeaf set 1 Jan as week 1, but the change
was missed in week_to_day() and in the man page.

Before
cal --week=40 --iso 1752
      October 1752
   Su Mo Tu We Th Fr Sa
41  1  2  3  4  5  6  7
42  8  9 10 11 12 13 14
43 15 16 17 18 19 20 21
44 22 23 24 25 26 27 28
45 29 30 31

Patched
cal --week=40 --iso 1752
     September 1752
   Su Mo Tu We Th Fr Sa
36                 1  2
37  3  4  5  6  7  8  9
38 10 11 12 13 14 15 16
39 17 18 19 20 21 22 23
40 24 25 26 27 28 29 30

Signed-off-by: J William Piggott <elseifthen@gmx.com>
misc-utils/cal.1
misc-utils/cal.c

index f99c6b4959e79376c1f1e0c9c87930bdd56e322d..60eaa5c3b83f78d011aac3f39ca4c49ef8b3558f 100644 (file)
@@ -195,13 +195,13 @@ highlighted if the calendar is displayed on a terminal.  If no parameters are
 specified, the current month's calendar is displayed.
 .SH NOTES
 A year starts on January 1.  The first day of the week is determined by the
-locale.
+locale or the
+.BR \-\-sunday \ and \ \-\-monday \ options.
 .PP
-The week numbering depends on the choice of the first day of the week.  If Sunday
-(the default) is used for the first day of the week, then the customary North
-American numbering will be used, i.e. the first Sunday of the year starts the
-first week.  If Monday is selected, then the ISO-8601 standard week numbering
-is used, where the first Thursday of the year is in week number 1.
+The week numbering depends on the choice of the first day of the week.  If it
+is Sunday then the customary North American numbering is used, where 1 January
+is in week number 1.  If it is Monday then the ISO 8601 standard week numbering
+is used, where the first Thursday is in week number 1.
 .SH COLORS
 Implicit coloring can be disabled as follows:
 .RS
index 894894ab6ded872606f1e9e3115d1b3da8b29de2..438e7f09b939f68cccef4fc36e5964a02083a5f4 100644 (file)
@@ -1003,7 +1003,7 @@ static int week_to_day(const struct cal_control *ctl)
        if (ctl->weektype & WEEK_NUM_ISO)
                yday -= (wday >= FRIDAY ? -2 : 5);
        else
-               yday -= (wday == SUNDAY ? 6 : -1);      /* WEEK_NUM_US */
+               yday -= 6;      /* WEEK_NUM_US */
        if (yday <= 0)
                return 1;