Created
November 18, 2017 15:28
-
-
Save augustovictor/ddbe6e92b2cc07ae3fab89c3e3e58f12 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
| /* | |
| Helper functions to calculate difference in hours, minutes and seconds between two dates | |
| */ | |
| function diffMinutes(initial, final) { | |
| if(initial > final) return 59 + final - initial | |
| return final - initial | |
| } | |
| function getDiffTime(initialDate, finalDate) { | |
| return { | |
| hours : Math.floor((finalDate - initialDate) / (1000 * 60 * 60)), | |
| minutes: diffMinutes(initialDate.getMinutes(), finalDate.getMinutes()), | |
| seconds: Math.abs(finalDate.getSeconds() - initialDate.getSeconds()) | |
| } | |
| } | |
| // Testing | |
| /* | |
| var releaseDate = new Date('2017-11-21T23:59:59') | |
| setInterval(function() {console.log(getDiffTime(new Date(), releaseDate))}, 1000) | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment