Last active
June 2, 2016 16:59
-
-
Save JDMcKinstry/d405bdc7d70ceeb92f18987e72045ab3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Date.prototype.add[Years|Months|Weeks|Days|Hours|Minutes|Seconds] */ | |
;(function() { | |
var methods = { | |
'addYears': function(v) { this.setFullYear(this.getFullYear() + parseFloat(v)); return this; }, | |
'addMonths': function(v) { this.setMonth(this.getMonth() + parseFloat(v)); return this; }, | |
'addWeeks': function(v) { this.addDays(7 * parseFloat(v)); return this; }, | |
'addDays': function(v) { this.setDate(this.getDate() + parseFloat(v)); return this; }, | |
'addHours': function(v) { this.setHours(this.getHours() + parseFloat(v)); return this; }, | |
'addMinutes': function(v) { this.setMinutes(this.getMinutes() + parseFloat(v)); return this; }, | |
'addSeconds': function(v) { this.setSeconds(this.getSeconds() + parseFloat(v)); return this; }, | |
}; | |
for (var k in methods) { | |
var v = methods[k]; | |
Object['defineProperty'] && !Date.prototype.hasOwnProperty(k) | |
? Object.defineProperty(Date.prototype, k, { value: v }) : Date.prototype[k] = v; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment