Skip to content

Instantly share code, notes, and snippets.

@fayewest
Created February 27, 2013 21:42
Show Gist options
  • Save fayewest/5052018 to your computer and use it in GitHub Desktop.
Save fayewest/5052018 to your computer and use it in GitHub Desktop.
(function(){
var p = Date.prototype;
p.val = 0;
p.add = function(num) {
this.val = num;
return this;
};
p.subtract = function(num) {
this.val = -num;
return this;
};
p.minutes = function() {
return new Date(this.getTime() + this.val*60000);
};
p.hours = function() {
return new Date(this.getTime() + this.val*60000*60);
};
p.days = function() {
return new Date(this.getTime() + this.val*60000*60*24);
};
p.weeks = function() {
return new Date(this.getTime() + this.val*60000*60*24*7);
};
p.months = function() {
return new Date(this.getTime() + this.val*60000*60*24*7*4);
};
p.years = function() {
return new Date(this.getTime() + this.val*60000*60*24*7*4*12);
};
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment