Nodejs Week Calculate getFullWeek()

Here you can find the source of getFullWeek()

Method Source Code

//sourced: http://stackoverflow.com/questions/12193626/week-year-picker-jquery-plugin

//Returns ISO 8601 week number and year
Date.prototype.getFullWeek = function(){
    var jan1, w, d = new Date(this);
    d.setDate(d.getDate()+4-(d.getDay()||7));   // Set to nearest Thursday: current date + 4 - current day number, make Sunday's day number 7
    jan1 = new Date(d.getFullYear(),0,1);       // Get first day of year
    w = Math.ceil((((d-jan1)/86400000)+1)/7);   // Calculate full weeks to nearest Thursday
    return {y: d.getFullYear(), w: w };
};
//Returns ISO 8601 week number
Date.prototype.getWeek = function(){ return this.getFullWeek().w; };
var getWeeksInYear = function(y){ return new Date(y,11,28).getFullWeek().w; };



//Usage:/*ww  w .j ava  2  s  .  c  o m*/

//console.log( getWeeksInYear( 2013 ) );
//console.log( new Date().getWeek() );

Related

  1. getDateOfISOWeek(w, y)
    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;
    };
    
  2. getDayofWeek()
    var daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
    Date.prototype.getDayofWeek = function() {
      return daysOfWeek[this.getDay()];
    
  3. 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));
    };
    
  4. getRealWeek()
    Date.prototype.getRealWeek = function()
        var monday = this;
        if (monday.getDay() < 1) {
            monday = monday.clone().next().monday();
        return monday.getWeek();
    };
    
  5. getStudyWeek()
    Date.prototype.getStudyWeek = function () {
      var inc = (this.getDay() == 6) ? 1 : 0;
      return this.getWeek() + inc;
    };
    
  6. moveToBeginOfWeek(weekStart)
    Date.prototype.moveToBeginOfWeek = function(weekStart)
        if (this.getDay() != weekStart) {
            this.moveToDayOfWeek(weekStart, -1);
        return this;
    };
    
  7. moveToEndOfWeek(weekStart)
    Date.prototype.moveToEndOfWeek = function(weekStart)
        var weekEndDay = weekStart + 6;
        if (weekEndDay > 6) {
            weekEndDay -= 7;
        if (this.getDay() != weekEndDay) {
            this.moveToDayOfWeek(weekEndDay, 1);
        return this;
    };