Back in 1965, The Beatles released their hit song 'Eight Days a Week'. In this code-golf challenge we are going to reimagine dates of the 21st century as if there really were eight days a week.
Input
A Gregorian calendar date between 1 January 2001 and 31 December 2100 inclusive. You may take input in any convenient format (including built-in date objects).
Output
The weekday number, week number, and week-numbering year (all defined below) corresponding to the input date. You may use any format (to be specified in your answer) in which all three numbers are unambiguously identifiable.
Week date system
The week date system, based on the ISO week date system but modified for eight-day weeks, works like this:
- Reckoning of dates begins on 1 January 2001 (Gregorian), which is weekday number 1 of week number 1 of week-numbering year 2001.
- Weeks begin on weekday number 1 and end on weekday number 8. (So 9 January 2001 is weekday number 1 of week number 2 of week-numbering year 2001.)
- Week number 1 of a week-numbering year is the week that contains 4 January.
- Week-numbering years contain exactly 45 or 46 weeks. Thus a week-numbering year begins on weekday number 1 of week number 1 and ends on weekday number 8 of week number 45 or 46.
Given that the number of days in a Gregorian calendar year is never a multiple of 8, the above rules have two important consequences:
- Week number 1 of a week-numbering year may begin in the last four days of December of the previous Gregorian year.
- Week number 46 (if there is one) of a week-numbering year may end in the first three days of January of the next Gregorian year.
Test cases
Input (Gregorian yyyy-mm-dd) -> Output (week-numbering year, week number, weekday number)
2001-01-01 -> 2001, 1,1
2001-01-08 -> 2001, 1,8
2001-01-09 -> 2001, 2,1
2001-12-31 -> 2001,46,5
2002-01-01 -> 2001,46,6
2002-01-04 -> 2002, 1,1
2002-12-29 -> 2002,45,8
2002-12-30 -> 2003, 1,1
2020-02-29 -> 2020, 8,7
2037-09-13 -> 2037,32,5
2061-04-23 -> 2061,15,4
2100-12-31 -> 2101, 1,4
Related, but that challenge involves standard 7-day weeks, has finicky I/O requirements, and bans date/time libraries and built-ins.