There is a solution: the International Standards Organisation (ISO) standard ISO8601:1988 defines week numbers.
ISO make their money from paper copies of standards, so the standard itself is not on line. However there is a number of abstracts available on the Web:
Week Number | Mon | Tue | Wed | Thu | Fri | Sat | Sun |
---|---|---|---|---|---|---|---|
1998W01 | 29 | 30 | 31 | 1 | 2 | 3 | 4 |
1998W02 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
1998W03 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
1998W04 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
1998W05 | 26 | 27 | 28 | 29 | 30 | 31 | 1 |
Week Number | Mon | Tue | Wed | Thu | Fri | Sat | Sun |
---|---|---|---|---|---|---|---|
1998W53 | 28 | 29 | 30 | 31 | 1 | 2 | 3 |
1999W01 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
1999W02 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
1999W03 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
1999W04 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Week Number | Mon | Tue | Wed | Thu | Fri | Sat | Sun |
---|---|---|---|---|---|---|---|
1999W52 | 27 | 28 | 29 | 30 | 31 | 1 | 2 |
2000W01 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
2000W02 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
2000W03 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
2000W04 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
2000W05 | 31 | 1 | 2 | 3 | 4 | 5 | 6 |
Sat Dec 27 12:00:00 1980 = 1980W52 Sun Dec 28 12:00:00 1980 = 1980W52 Mon Dec 29 12:00:00 1980 = 1980W53 <== Tue Dec 30 12:00:00 1980 = 1980W53 <== Wed Dec 31 12:00:00 1980 = 1980W53 <== Thu Jan 01 12:00:00 1981 = 1981W01 Fri Jan 02 12:00:00 1981 = 1981W01
As Tcl and Perl use strftime() for their time routines, the same applies.
With systems which support the %V format character in strftime(), one can put some extra checks in to solve the problem at the year transition. For example, here is a Tcl routine for calculating ISO 8601:1988 week numbers.
For older flavours of Unix which don't support the %V format character in strftime(), I have written a utility in C to return the ISO 8601:1988 week number in the format specified in the standard, e.g. 1998W25
I've ported the C code to a Perl script to return the ISO 8601:1988 week number in the format specified in the standard, e.g. 1998W25. It's not neat Perl, but it gives the same results as the C code for my test program.
There's also Perl library code to return the time since the epoch of the start of the week given the week number, which can be used with Perl code to return the date of the start of the week given the week number.