Created
July 6, 2015 18:41
-
-
Save miere/22d1c0c3b6a40b98ba10 to your computer and use it in GitHub Desktop.
Very tiny utility for date manipulation.
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
| /** | |
| * 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