Nodejs Date Add dateAdd(interval, number)

Here you can find the source of dateAdd(interval, number)

Method Source Code

Date.prototype.dateAdd = function (interval, number) {
    var d = new Date(this);
    var k = { 'y': 'FullYear', 'q': 'Month', 'm': 'Month', 'w': 'Date', 'd': 'Date', 'h': 'Hours', 'n': 'Minutes', 's': 'Seconds', 'ms': 'MilliSeconds' };
    var n = { 'q': 3, 'w': 7 };
    eval('d.set' + k[interval] + '(d.get' + k[interval] + '()+' + ((n[interval] || 1) * number) + ')');
    return d;//from   w  w  w .j a  va  2s.  c o m
}

Related

  1. add(amount,field)
    Date.prototype.add=function(amount,field){
      if(amount){
        switch (field)
          case "y":
            this.setFullYear(this.getFullYear() + amount);
            break;
          case "q":
            this.setMonth(this.getMonth() + amount * 3);
    ...
    
  2. add(interval, value)
    Date.MILLI = 'ms';
    Date.SECOND = 's';
    Date.MINUTE = 'mi';
    Date.HOUR = 'h';
    Date.DAY = 'd';
    Date.MONTH = 'mo';
    Date.YEAR = 'y';
    Date.prototype.add = function(interval, value){
      var d = this.clone();
    ...
    
  3. add(thisMany)
    Date.prototype.add = function(thisMany) {
      var self = this;
      return { minutes: function() {
        var newDate = new Date(self);
        newDate.setMinutes(self.getMinutes() + thisMany);
        return newDate; }};
    };
    
  4. addDate(num)
    Number.prototype.addDate=function(num){
        var date=this;
        var dates=[];
        var d=new Date(Number(date).dateFormat());
        d.setDate(d.getDate()+(num));
        dates.push(d.getFullYear());
        dates.push(Number(d.getMonth()+1).addZero());
        dates.push(Number(d.getDate()).addZero());
        var next_date=dates.join("");
    ...
    
  5. addMilliseconds(value)
    Date.prototype.addMilliseconds = function(value)
        this.setTime(this.getTime() + value);
        return this;
    };
    
  6. dateAdd(interval, number)
    Date.prototype.dateAdd = function (interval, number) {
        var d = this;
        var k = {
            'y': 'FullYear',
            'q': 'Month',
            'm': 'Month',
            'w': 'Date',
            'd': 'Date',
            'h': 'Hours',
    ...
    
  7. dateAdd(size,value)
    Date.prototype.dateAdd = function(size,value) {
        value = parseInt(value);
        var incr = 0;
        switch (size) {
            case 'year':
                this.setFullYear(this.getUTCFullYear()+value);
                break;
            case 'month':
                value = value + this.getUTCMonth();
    ...