Thanks for the code. If it is true that ISO week numbers are different from US week numbers I'm not sure we want to touch this, it might be better for sites to implement their own as their needs dictate (based on audience etc). The wikipedia hints that there are even more systems in use (search for "week number"; the references from that page back this up to an extent).
--lars On 7/24/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I noticed, there's no support for (ISO) week numbers. That is actually > quite popular in Europe. One thing of importance, is they differ from > American week numbers. > > Is there time/room for improvements? > > I think the implementation effort is quite moderate. I wrote the > following code a while ago (although I now would return 1-based week > numbers): > ---8<----------------------------------------------------------------------------- > //Like valueOf(), only resolution in days, not ms. > Date.prototype.valueInDays=function() { > return parseInt(new Date(this.getFullYear(), > this.getMonth(), > this.getDate()).valueOf()/(24*60*60*1000)); > } > //Day of week, zero-based (monday=0, sunday=6) > Date.prototype.getWeekDay=function() { > return this.getDay()==0 ? 6 : this.getDay()-1; > } > //Week number according to ISO-8601, zero-based (1 is 2nd week). > Date.prototype.getWeekNr=function() { > var x = new Date(this.getFullYear(),0,1); > x.setDate([0,0,0,0,3,2,1][x.getWeekDay()]+x.getDate()); > if(this.valueInDays() < x.valueInDays()) > return new Date(this.getFullYear()-1,12-1,31).getWeekNr(); > else > return parseInt((this.valueInDays()-x.valueInDays()+x.getWeekDay())/7,10); > } > ---8<----------------------------------------------------------------------------- > Thanks, > -- > |\ > | \ > |_/oeke > [EMAIL PROTECTED] > _______________________________________________ > Es4-discuss mailing list > Es4-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es4-discuss > _______________________________________________ Es4-discuss mailing list Es4-discuss@mozilla.org https://mail.mozilla.org/listinfo/es4-discuss