Returns an array of day objects which occur after the specified date - Node.js Date

Node.js examples for Date:Day

Description

Returns an array of day objects which occur after the specified date

Demo Code

/**//from   w ww.j av  a2  s  .  c o m
 * Date.getDaysAfterDate()
 * returns an array of day objects which occur after the specified date
 *
 * @date
 *    the date object from which you need to retrieve the subsequent days of the month
 */
Date.prototype.getDaysAfterDate = function() {
  //declare vars
  var i;
  var iterdate = this;
  var array = []
  var n = 0;
  var oneDay = 1000 * 60 * 60 * 24;
  //@TODO: allow for this function to receive both a date or timestamp

  //loop through to get total number of days in the month remaining
  //we can determine this by looping through and adding a day to the current day until the month is different from the current month

  for(i = this.getDate() + 1; i < 50; i++) { //starting at the current day, count up until the month is not the same as the current month
    //calculate the day's timestamp
    iterdate = new Date(iterdate.getTime() + oneDay); //get a new object from the iterdate + one day

    if(iterdate.getMonth() != this.getMonth()) {
      break;
      i = 0;
    }
    else {
      array[n] = iterdate;
    }

    n++; //iterate n
  }

  return array;

};

Related Tutorials