Date::Calc has a Week_of_Year method that should give you what you're looking for | [reply] |
$ perl -MPOSIX -le'print strftime q/%W/, localtime'
35
| [reply] [d/l] |
| [reply] [d/l] [select] |
$doy = (localtime)[7]; # day of year
$wk = int($doy/7);
$wk++ if $doy % 7;
| [reply] [d/l] |
This won't work. For example Jan 1. 2005 is first day. But week 53 (at least in Germany) of 2004.
The OP also didn't take into account that the rules in different countries might differ. For example: In Germany weeks start on Mondays, in the US they start on Sundays (if I remember correctly). So the german calendar week rule is slightly differnt from the american. If I remember correctly week 1 of a given year is the week containing the first Wednesday of a year.
s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
| [reply] [d/l] [select] |
Interesting, and apologies. Does Date::Calc take this into account? Presumably POSIX::strftime is locale sensitive?
| [reply] |
In the US, it's a bit more complicated than "Sunday is the first day of the week." Calendars do have Sunday first. Most US companies where I've worked started their week on Monday. Some start their week on Sunday. I vaguely remember working at one which started its week on Saturday.
Even disregarding which day starts the week, when week 1 starts varies.
emc
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.
Albert Einstein
| [reply] |