#995028 ncal: incorrect week numbers listed when using -w option

Package:
ncal
Source:
bsdmainutils
Description:
display a calendar and the date of Easter
Submitter:
Andy Bussman
Date:
2022-03-31 09:57:07 UTC
Severity:
normal
#995028#5
Date:
2021-09-24 23:33:54 UTC
From:
To:
Dear Maintainer,

ncal lists incorrect week numbers when using the -w option.

Week numbers do not conform in the ISO-8601 standard, even though the
man page states that the "-w" option is ISO-8601 compliant.

For example, when producing a calendar for today (2021-09-24):

  $ ncal -w

ncal outputs the following:

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

Which incorrectly lists today's week number as "39" when the correct
ISO-8601 week number for 2021-09-24 is W38.

The correct week number can be verified using the date command:

  $ date -d "2021-09-24" +%W
  38

This seems to be caused by ncal miscounting the first week for the year:

  $ ncal -b -w 2021
                                       2021
           January                   February                     March
   w| Su Mo Tu We Th Fr Sa    w| Su Mo Tu We Th Fr Sa    w| Su Mo Tu We Th Fr Sa
   1|                 1  2    6|     1  2  3  4  5  6   10|     1  2  3  4  5  6
   2|  3  4  5  6  7  8  9    7|  7  8  9 10 11 12 13   11|  7  8  9 10 11 12 13
   3| 10 11 12 13 14 15 16    8| 14 15 16 17 18 19 20   12| 14 15 16 17 18 19 20
   4| 17 18 19 20 21 22 23    9| 21 22 23 24 25 26 27   13| 21 22 23 24 25 26 27
   5| 24 25 26 27 28 29 30   10| 28                     14| 28 29 30 31
   6| 31

            April                       May                       June
   w| Su Mo Tu We Th Fr Sa    w| Su Mo Tu We Th Fr Sa    w| Su Mo Tu We Th Fr Sa
  14|              1  2  3   18|                    1   23|        1  2  3  4  5
  15|  4  5  6  7  8  9 10   19|  2  3  4  5  6  7  8   24|  6  7  8  9 10 11 12
  16| 11 12 13 14 15 16 17   20|  9 10 11 12 13 14 15   25| 13 14 15 16 17 18 19
  17| 18 19 20 21 22 23 24   21| 16 17 18 19 20 21 22   26| 20 21 22 23 24 25 26
  18| 25 26 27 28 29 30      22| 23 24 25 26 27 28 29   27| 27 28 29 30
                             23| 30 31

            July                      August                    September
   w| Su Mo Tu We Th Fr Sa    w| Su Mo Tu We Th Fr Sa    w| Su Mo Tu We Th Fr Sa
  27|              1  2  3   32|  1  2  3  4  5  6  7   36|           1  2  3  4
  28|  4  5  6  7  8  9 10   33|  8  9 10 11 12 13 14   37|  5  6  7  8  9 10 11
  29| 11 12 13 14 15 16 17   34| 15 16 17 18 19 20 21   38| 12 13 14 15 16 17 18
  30| 18 19 20 21 22 23 24   35| 22 23 24 25 26 27 28   39| 19 20 21 22 23 24 25
  31| 25 26 27 28 29 30 31   36| 29 30 31               40| 26 27 28 29 30


           October                   November                   December
   w| Su Mo Tu We Th Fr Sa    w| Su Mo Tu We Th Fr Sa    w| Su Mo Tu We Th Fr Sa
  40|                 1  2   45|     1  2  3  4  5  6   49|           1  2  3  4
  41|  3  4  5  6  7  8  9   46|  7  8  9 10 11 12 13   50|  5  6  7  8  9 10 11
  42| 10 11 12 13 14 15 16   47| 14 15 16 17 18 19 20   51| 12 13 14 15 16 17 18
  43| 17 18 19 20 21 22 23   48| 21 22 23 24 25 26 27   52| 19 20 21 22 23 24 25
  44| 24 25 26 27 28 29 30   49| 28 29 30                1| 26 27 28 29 30 31
  45| 31

The first week in January 2021 is incorrectly indicated as week "1".
According to ISO-8601 the first week of the year is the week that
contains that year's first Thursday.  As such, the first week in January
2021 should be "0" and the week with the first Thursday should be "1".

Thank you,

Andrew

#995028#10
Date:
2022-03-31 09:52:13 UTC
From:
To:
 ❦ 24 September 2021 16:33 -07, Andy Bussman:

FI, the bug is also present upstream.