Skip to content

Instantly share code, notes, and snippets.

@PMaynard
Last active August 29, 2015 13:58
Show Gist options
  • Save PMaynard/10399272 to your computer and use it in GitHub Desktop.
Save PMaynard/10399272 to your computer and use it in GitHub Desktop.
Next Bus Please
/* 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