Among all the stupid calendar "innovations" brought about by mindless bureaucrats, week numbers are exceptional in their blatant disregard for elementary mathematics. The only timekeeping mistake that is actually more stupid than week numbers is Daylight Saving Time (see the page "UTC in crontabs" for my thoughts on DST).
Week numbering is based on the idea that a calendar year is composed of a set of distinct weeks, similarly to how the year is composed of a set of distinct months. This is obviously stupid since weeks are always 7 days long, while a year is either 365 or 366 days long. Any idiot armed with a calculator is able to immediately determine that neither 365 nor 366 can be divided by 7. So it obviously won't work, unless at least one week every year gets a different length than 7 days. This is, as most adults know, how the 12 months of the calendar are made to always fit into a year: they are assigned different lengths, designed to match up. But it doesn't work for weeks since all weeks have the same length, and the length of any given year is never divisible by the week length. Sorry for repeating this fact, but the persistence of week numbering is evidence that this simple mathematical truth is beyond the mental grasping powers of many people, especially the ones who invented week numbers.
There is even an ISO standard for week numbering, as described in ISO 8601. This standard essentially says that the first Thursday of a year defines the containing week to be "Week 1" of that year. The same standard arbitrarily defines the beginning of the week to be Monday, contradicting older established conventions where the week began with Sunday. The ISO 8601 standard also changes the beginning and end of a year so that they match the first day of "Week 1" and the last day of "Week 52" (or "Week 53") respectively. For example: Sunday January 2, 2005 doesn't belong to any week of 2005. It belongs to week 53 of 2004 and no other, according to the standard. So even the concept of what a calendar year means is damaged by the stupidity of week numbering.
Unfortunately, stupidity is never easily abolished. Even if the concept of week numbering were to be discarded tomorrow morning, it would still be necessary for historical researchers to be able to calculate week numbers. To facilitate this, I have written some Perl code that calculates the week number for a given time coordinate. The subroutine weeknum returns the year (which may be different from the actual astronomical year — see above), the ISO 8601 week number, and the day of the week starting with 1 for Monday. It should be fairly obvious how to translate the code to other programming languages. Just do "man ctime" to find the meaning of the $tm indices. Here is the code:
my @tm = localtime(time); my $y = $tm[5]; sub daynum { my $yday = shift; return 365*$y + int(($y-1)/4) + $yday - 25564; } sub weeknum { my $index0 = &daynum(0); my $index = &daynum($tm[7]); my $weekday0 = $index0 % 7; my $weekday = $index % 7; if ($tm[4] == 11 && $tm[3] - $weekday >= 29) { return ($y + 1901, 1, $weekday + 1); } else { $index0 -= $weekday0; if ($weekday0 > 3) { $index0 += 7; if ($index < $index0) { $y--; $index0 = &daynum(0); $weekday0 = $index0 % 7; $index0 += 7 if $weekday0 > 3; } } return ($y + 1900, int(($index - $index0) / 7) + 1, $weekday + 1); } } printf "%d-W%02d-%d\n", &weeknum();