# week_number

Definition: | sequence res = week_number(object y, integer m=0, d=0)
Description: | y: a year such as 2022, or a result from date() or a timedate. m: a month 1..12, ignored/overidden if y is a sequence. d: a day 1..31, ignored/overidden if y is a sequence. Returns {y[-1],1..52}
pwa/p2js: | Supported.
Comments: | Note that days prior to the first Monday of the year are classed as week 52 of the preceding year. Fairly obviously, week_number({2022,12,15}) yields the same result as week_number(2022,12,15), and week_number({2022}) will simply crash because the sequence isn’t long enough/has no month or day. No special protection is afforded for, say, the 31st of February, or other invalid months/days (as yet). Not suitable for use with years prior to the introduction of the Gregorian calendar. Returns 0 if y < 1752.
Example: |
    ?week_number(2022,1,1)      -- prints {2021,52}     -- (A Saturday)
    ?week_number(2022,1,2)      -- prints {2021,52})    -- (A Sunday)
    ?week_number(2022,1,3)      -- prints {2022,1})     -- (The first Monday)
    ?week_number(2022,1,4)      -- prints {2022,1})     -- (Tuesday)
    ?week_number(2022,1,9)      -- prints {2022,1})     -- (Sunday)
    ?week_number(2022,1,10)     -- prints {2022,2})     -- (The second Monday)
    ?week_number(2022,12,31)    -- prints {2022,52})    -- (New Years Eve)
Implementation: | See builtins\pdates.e (an autoinclude) for details of the actual implementation.
See Also: | date, day_of_week