Resolution for bug in ShowWeekNumber option of datepicker

Resolution for bug in ShowWeekNumber option of datepicker

florincoflorinco Posts: 2Questions: 1Answers: 0
edited May 2016 in Editor

ShowWeekNumbers gives the wrong weeknumber.
Week of the year according to ISO 8601 standard first week of the year is the week of the first Thursday of a year.

If you want to patch this: override _htmlWeekOfYear function in dataTables.editor.min.js

, _htmlWeekOfYear: function (a, b, c) {
    var d = new Date(c, b, a);
    d.setHours(0, 0, 0);

    // Make Sunday's day number 7
    var dayNo = (d.getDay() || 7);

    // Set to nearest Thursday: current date + 4 - current day number
    d.setDate(d.getDate() + 4 - dayNo);
    // Get first day of year
    var yearStart = new Date(d.getFullYear(), 0, 1);
    // Calculate full weeks to nearest Thursday
    var weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);

    return '<td class="' + this.c.classPrefix + '-week">' + weekNo + '</td>';
}

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Thanks for posting this!

    I'll look over this in detail and get it into the next release of Editor. I'll post back here when done.

    Allan

  • florincoflorinco Posts: 2Questions: 1Answers: 0

    you're welcome!

  • VyacheslavVyacheslav Posts: 70Questions: 27Answers: 0

    +1

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Somewhat delayed reply I'm afraid, but the correct calculation for the ISO8601 week number will be included in Editor 1.6.

    Regards,
    Allan

This discussion has been closed.