Nodejs Week Calculate getDateOfISOWeek(w, y)

Here you can find the source of getDateOfISOWeek(w, y)

Method Source Code

/**//w w  w.  j a v a  2 s. com
 * Find week's first day
 * @param  {number} w week number
 * @param  {number} y year
 * @return {date}
 */
Date.prototype.getDateOfISOWeek = function (w, y) {
  var simple = new Date(y, 0, 1 + (w - 1) * 7);
  var dow = simple.getDay();
  var ISOweekStart = simple;

  if (dow <= 4) ISOweekStart.setDate(simple.getDate() - simple.getDay() + 1);
  else ISOweekStart.setDate(simple.getDate() + 8 - simple.getDay());
  return ISOweekStart;
};

Related

  1. getDayofWeek()
    var daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
    Date.prototype.getDayofWeek = function() {
      return daysOfWeek[this.getDay()];
    
  2. getFirstDayOfWeek()
    Date.prototype.getFirstDayOfWeek = function()
        "use strict";
        var temp = new Date(this.getTime());
        var distance = (temp.getDay()-1).mod(7);
        return new Date(this.getTime() - (distance * 86400000));
    };
    
  3. getFullWeek()
    Date.prototype.getFullWeek = function(){
        var jan1, w, d = new Date(this);
        d.setDate(d.getDate()+4-(d.getDay()||7));   
        jan1 = new Date(d.getFullYear(),0,1);       
        w = Math.ceil((((d-jan1)/86400000)+1)/7);   
        return {y: d.getFullYear(), w: w };
    };
    Date.prototype.getWeek = function(){ return this.getFullWeek().w; };
    var getWeeksInYear = function(y){ return new Date(y,11,28).getFullWeek().w; };
    ...
    
  4. getRealWeek()
    Date.prototype.getRealWeek = function()
        var monday = this;
        if (monday.getDay() < 1) {
            monday = monday.clone().next().monday();
        return monday.getWeek();
    };