Last active
August 29, 2015 13:58
-
-
Save PMaynard/10399272 to your computer and use it in GitHub Desktop.
Next Bus Please
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
/* bus-times.json | |
{ | |
"fromScience": [ | |
{ "hr": 12, "min": 30 }, | |
{ "hr": 16, "min": 0 }, | |
{ "hr": 16, "min": 30 }, | |
{ "hr": 17, "min": 0 }, | |
{ "hr": 17, "min": 45 }, | |
{ "hr": 19, "min": 0 } | |
] | |
} | |
*/ | |
var d = new Date(), times_raw = require('./bus-times.json') | |
for(i in times_raw.fromScience){ | |
var a = new Date(d.getFullYear(),d.getMonth(),d.getUTCDate(),times_raw.fromScience[i].hr, times_raw.fromScience[i].min); | |
if(d < a ) { | |
var diff = a - d, s = Math.round((diff / 1000) % 60), min = Math.round((diff / (1000*60)) % 60), hr = Math.round((diff / (1000*60*60)) % 24); | |
console.info(a.getHours(), a.getMinutes(), hr, 'Hr', min, 'Min', s, 'Sec'); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment