week number for date/time proposal

doekman at gmail.com doekman at gmail.com
Mon Jul 23 15:56:28 PDT 2007

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
//Like valueOf(), only resolution in days, not ms.
Date.prototype.valueInDays=function() {
  return parseInt(new Date(this.getFullYear(),
//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);
  if(this.valueInDays() < x.valueInDays())
    return new Date(this.getFullYear()-1,12-1,31).getWeekNr();
    return parseInt((this.valueInDays()-x.valueInDays()+x.getWeekDay())/7,10);
| \
doekman at gmail.com

More information about the Es4-discuss mailing list