Calendar in date picker gets week numbers wrong

XMLWordPrintable

    • 4

      The calendar in the date picker numbers weeks (along the left). However it gets the week numbers wrong. It seems to be trying to implement the numbering scheme described in ISO-8601 (see this summary):

      /** Returns the number of the week in year, as defined in ISO 8601. */
      Date.prototype.getWeekNumber = function() {
          var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
          var DoW = d.getDay();
          d.setDate(d.getDate() - (DoW + 6) % 7 + 3); // Nearest Thu
          var ms = d.valueOf(); // GMT
          d.setMonth(0);
          d.setDate(4); // Thu in Week 1
          return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1;
      };
      

      However it seems to be buggy (see for example week numbers in 2004).

      update:
      There is a workaround for this issue in 3.13.x and 4.0.x. Thanks to Bettina Zucker for this solution. See the comment here.

            Assignee:
            Mark Lassau (Inactive)
            Reporter:
            Jeff Turner
            Votes:
            10 Vote for this issue
            Watchers:
            17 Start watching this issue

              Created:
              Updated:
              Resolved: