www.eamoncaddigan.net

Content and configuration for https://www.eamoncaddigan.net
git clone https://git.eamoncaddigan.net/www.eamoncaddigan.net.git
Log | Files | Refs | Submodules | README

commit 1774ff75d7f1db9401c0082ebddc4c7f5b4e89cb
parent 958be8507462f6368810899ccbcfdcc33f72368f
Author: Eamon Caddigan <eamon.caddigan@gmail.com>
Date:   Tue,  1 Aug 2023 20:31:50 -0700

Simple post about week numbers

Diffstat:
Acontent/posts/iso-week/index.md | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 71 insertions(+), 0 deletions(-)

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