Skip to content

Instantly share code, notes, and snippets.

@miere
Created July 6, 2015 18:41
Show Gist options
  • Select an option

  • Save miere/22d1c0c3b6a40b98ba10 to your computer and use it in GitHub Desktop.

Select an option

Save miere/22d1c0c3b6a40b98ba10 to your computer and use it in GitHub Desktop.
Very tiny utility for date manipulation.
/**
* Sample:
* new Date().add( 20, Date.DAY ) // will point to 20 ahead from today
* new Date().add( -20, Date.DAY ) // will point to 20 ago from today
*/
Date.SECOND = 1000
Date.MINUTE = (60*Date.SECOND)
Date.HOUR = (60*Date.MINUTE)
Date.DAY = (24*Date.HOUR)
Date.prototype.add = function( size, unit ){
unit = unit || Date.SECOND
size = size || 0
return new Date( this.getTime() + (size*unit) )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment