Well it's the easy way, but there is a problem with it:
It works fine for 2001, because the first day of the first week of that year happens to be a MONDAY.
But when we get to 2002 the first day of the first week is a TUESDAY.
Now strftime("%W",mktime(0,0,0,$01,$01,$2002));
returns weeknumber '0' ..not '1'
only the first FULL week of a year (beginning on a monday) will start the weekcounter at 1.
So if you find it wrong to call the first week of the year 2002 'week 0' - and my calender calls it week 1 - then you have a problem. And it offsets all the weeks of that year by one ofcourse... I guess you have to compute the weeknumber in your own routine... I looked for the solution for a while, but havent found one, other than to do the math. (but the computer will do that VERY fast 😉
here's an quick idea I just got (but its not thought through or tested):
For every year it goes:
Either the first day of the year is a monday, and then we can use strftime(%W)
Else the first day of the year is NOT a monday: in that case $weeknumber = strftime(%W)+1
It will never be offset more than 1
.. i guess?