Created
February 16, 2015 15:29
-
-
Save aldraco/e76c8f089485ddc9b0f7 to your computer and use it in GitHub Desktop.
Reddit /dailyprogrammer challenge from Feb 09, 2015.
This file contains 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
module.exports = function(input) { | |
//take input string and parse to a date object. | |
var targetDate = Date.parse(input); | |
//figure out the current date, in a date object | |
var todaysDate = Date.now(); | |
//find the difference between the two dates | |
var difference = targetDate - todaysDate; | |
//convert the difference to days. | |
/* Round up to include today as a "day," i.e. it's | |
one day until tomorrow, even though it's represented | |
as a few hours. */ | |
difference = Math.ceil(difference / 86400000); | |
todaysDate = todaysDate.toString(); | |
return difference + " days from 2015 2 16 to "+input; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment