# errors in ISO week number

Arnold D. Robbins arnold at skeeve.atl.ga.us
Sun Dec 31 20:17:00 UTC 1995

```Hello Hume,

> Don Libes <libes at cme.nist.gov> has pointed me to you directly...
> i had mentioned that the ISO week of Jan 1 was never 52
> with the code he'd had, although just over 1 time in 7
> it should be.  he got new code from you, which seems
> to have the right week for Jan 1 but not always Dec 1 -
> it should sometimes be in week 1 of "next" year...
>
> e.g.  1973 Dec 31  should be in week 1 of 1974.

I think I disagree rather strongly with this. Dec 31 should always be
in the last week of the year. This just makes sense. The question is
whether it's week 52 or week 53.

Unless the ISO standard actually *says* that it's in week 1 of the
following year, I don't want to change my code... (And if it does say
that, then In My Not So Humble Opinion it's silly.)

> i've taken a very different technique for calculating ISO week numbers
> in some code of my own.  (i was comparing it to expect's timestamp, which
> uses your code, and the calendar stuff in emacs 19.30)  although it's
> only designed to work for 100 years (i assume a leap year every four years,
> so after 2100 Feb 28 i'll be a day off, etc), it's so much simpler you may
>
> x = ut/(60*60*24)	number of days = unix time / length of day
> x = x + 3		adjust to the previous monday
> ISOday = 1 + x%7	weekday
> x = x/7			number of weeks
> y = (28*x+2)/1461	number of years
> x = x - (1461*y+25)/28	number of weeks into year
> ISOyear = 1970+y
> ISOweek = 1+x
>
> (the divisions should be C integer divisions)
>
> the best way to fix it for the rest of the gregorian cycle is probably
> to change the 2 and the 25.  note that whatever they're changed to, must
> sum to 27.  (if you're interested in this method, i'll try to complete
> it for you if you'd prefer...)
> --
> Hume Smith   <hclsmith at isisnet.com>   NetBSD r00lz :)
>
>
> Real Americans don't carry cash.  Their police may steal it.d