Nodejs Week Calculate offsetByWeek(offset)

Here you can find the source of offsetByWeek(offset)

Method Source Code

Date.prototype.offsetByWeek = function(offset) {
    this.setTime(this.getTime() + offset * (7 * 24 * 60 * 60 * 1000));
    return this;/*from w w  w .  j  a  v  a2s. co  m*/
};

Related

  1. 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; };
    ...
    
  2. getRealWeek()
    Date.prototype.getRealWeek = function()
        var monday = this;
        if (monday.getDay() < 1) {
            monday = monday.clone().next().monday();
        return monday.getWeek();
    };
    
  3. getStudyWeek()
    Date.prototype.getStudyWeek = function () {
      var inc = (this.getDay() == 6) ? 1 : 0;
      return this.getWeek() + inc;
    };
    
  4. moveToBeginOfWeek(weekStart)
    Date.prototype.moveToBeginOfWeek = function(weekStart)
        if (this.getDay() != weekStart) {
            this.moveToDayOfWeek(weekStart, -1);
        return this;
    };
    
  5. 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;
    };
    
  6. subWeeks(value)
    Date.prototype.subWeeks = function(value) {
      this.subDays(value * 7);
      return this;
    };
    
  7. toWeekDays()
    Date.prototype.toWeekDays = function () {
      var weekday = this.clone()
      if (!weekday.is().sunday()) {
        weekday.sunday().add(-7).days()
      var week = [weekday.clone()]
      for (var day = 0; day < 6; day++) {
        week.push(weekday.add(1).days().clone())
      return week
    Date.prototype.toNextWeekDays = function () {
      return this.add(7).days().toWeekDays()
    Date.prototype.toPreviousWeekDays = function () {
      return this.add(-7).days().toWeekDays()
    Date.prototype.compare = function (date) {
      var year = this.getYear() - date.getYear()
      if (year > 0)
        return "In " + year + " Years"
      else if (year < 0)
        return -year + " Years Ago"
      else {
        var month = this.getMonth() - date.getMonth()
        if (month > 0)
          return "In " + month + " Months"
        else if (month < 0)
          return -month + " Months Ago"
        else {
          var week = this.getWeekOfYear() - date.getWeekOfYear()
          if (week > 0)
            return "In " + week + " Weeks"
          else if (week < 0)
            return -week + " Weeks Ago"
          else {
            if (this.getDay() - date.getDay() == 0)
              return "Today"
            else
              return this.toString("dddd")
    
  8. toWeekEnd(startsFromSunday)
    Date.prototype.toWeekEnd = function (startsFromSunday) {
        var dayOfWeek = this.getDay();
        if (startsFromSunday) {
            return this.addDays(6 - dayOfWeek);
        if (dayOfWeek == 0) {
            dayOfWeek = 7;
        return this.addDays(7 - dayOfWeek);
    ...
    
  9. toWeekStart(startsFromSunday)
    Date.prototype.toWeekStart = function (startsFromSunday) {
        var dayOfWeek = this.getDay();
        if (startsFromSunday) {
            return this.addDays(-dayOfWeek);
        if (dayOfWeek == 0) {
            dayOfWeek = 7;
        return this.addDays(1 - dayOfWeek);
    ...