index.md (2776B)
1 --- 2 title: "ISO week" 3 date: 2023-08-02T19:48:25-07:00 4 draft: false 5 categories: 6 - Programming 7 --- 8 9 Every nerd knows that [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) is 10 the "correct" way to display dates, but those who dig into the standard know 11 that it encompasses more than YYYY-MM-DD format[^isotime]. One of the 12 stranger conformant formats uses week number; today's date in this format is 13 2023-W31-3; i.e., today is the third day of the 31st week of 2023. 14 15 I've been using this format for note-taking for a couple years. I find it 16 easier to track to-dos with this because it's so easy to tell at a glance 17 how many weeks and days I have to finish something. 18 19 In a POSIX command-line, you can print ISO-8601 week date with: 20 21 ```sh 22 date +%G-W%V-%u 23 ``` 24 In Vim, use: 25 26 ```vim 27 :put =strftime('%G-W%V-%u') 28 ``` 29 30 I'm not here to convince you to _give up months_ or anything; there are 31 plenty of confusing things about this format: 32 33 * Nobody will know what you mean if you try to talk about "week 31" 34 * Years have different numbers of weeks (52 or 53) 35 * Unless the year happens to begin on Monday, either the beginning of 36 January or end of December fall on a different year than the rest of that 37 month (which is why you need `%G` instead of `%Y` in the date format 38 string) 39 40 ## ISO and epi weeks 41 42 I worked with week numbers when I helped conduct [research on Influenza-like 43 illness](https://doi.org/10.1001/jamanetworkopen.2022.11958). The CDC 44 publishes a [weekly surveillance 45 report](https://www.cdc.gov/flu/weekly/index.htm), and week 40 is 46 traditionally recognized as the beginning of each flu season. The CDC also 47 use week numbers to track other diseases, such as Covid-19. 48 49 Unfortunately, CDC weeks (aka "epidemiological weeks", or "epi weeks") 50 aren't ISO weeks; the former start on Sunday while the latter start on 51 Monday, which means that Sundays will have different week numbers between 52 the two systems. Except, more confusingly, when January 1 falls on a 53 Thursday (as it will in 2026)---then _only_ Sunday has the same week number, 54 and the epi week will be one behind the ISO week for the other days. This 55 table shows the ISO week and epi week of the first Monday of the year, 56 ordered by the day that the year starts, and illustrates some of the issues 57 with week-based dates. 58 59 January 1 | First Monday | ISO week | Epi week 60 ----------|--------------|----------|--------- 61 Monday | January 1 | 1 | 1 62 Tuesday | January 7 | 2 | 2 63 Wednesday | January 6 | 2 | 2 64 Thursday | January 5 | 2 | 1 65 Friday | January 4 | 1 | 1 66 Saturday | January 3 | 1 | 1 67 Sunday | January 2 | 1 | 1 68 69 [^isotime]: [Here's a cool 70 visualization](https://ijmacd.github.io/rfc3339-iso8601/) of date and time 71 formats.