]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
cal: fix week calculations for 1752
authorJ William Piggott <elseifthen@gmx.com>
Mon, 22 Jan 2018 12:01:23 +0000 (07:01 -0500)
committerKarel Zak <kzak@redhat.com>
Mon, 22 Jan 2018 13:16:57 +0000 (14:16 +0100)
Before:
cal --week=39 1752
     September 1752
   Su Mo Tu We Th Fr Sa
36        1  2 14 15 16
37 17 18 19 20 21 22 23
38 24 25 26 27 28 29 30

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

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

index c2e2913e721b821f7bcc185be122485dca92de0d..894894ab6ded872606f1e9e3115d1b3da8b29de2 100644 (file)
@@ -997,6 +997,9 @@ static int week_to_day(const struct cal_control *ctl)
        wday = day_in_week(ctl, 1, JANUARY, ctl->req.year);
        yday = ctl->req.week * DAYS_IN_WEEK - wday;
 
+       if (ctl->req.year == ctl->reform_year && yday >= YDAY_AFTER_MISSING)
+               yday += NUMBER_MISSING_DAYS;
+
        if (ctl->weektype & WEEK_NUM_ISO)
                yday -= (wday >= FRIDAY ? -2 : 5);
        else