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

Node.js examples for Date:Day

Description

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

Demo Code


/**//from w w  w.  j  a va2  s  . c o  m
 * Date.getDaysAfterMonth()
 * returns an array of day objects which occur after the month of the specified date
 *
 * @date
 *    the date object from which you need to retrieve the previous days of the month
 */
Date.prototype.getDaysAfterMonth = function() {
  //declare vars
  var i;
  var iterdate = this;
  var array = []
  var n = 0;
  var oneDay = 1000 * 60 * 60 * 24;
    //we'll need to fill in until 0 with days from previous month
    //add those to the matrix

  //figure out the day of the week the last day is on
    //fill in array until 6 with days from the next month
    //add those to the matrix

  for(i =  this.getDay(); i < 6; i++) { //starting at the current day, count down until i is no longer > 0
    //calculate the day's timestamp
    iterdate = new Date(iterdate.getTime() + oneDay); //get a new object from the iterdate + one day

    array[n] = iterdate;

    n++; //iterate n

  }

  //return the array
  return array;

};

Related Tutorials