Skip to content

Instantly share code, notes, and snippets.

@maxdeepfield
Created October 26, 2015 12:40
Show Gist options
  • Save maxdeepfield/fc1a53e6f71bdbbeaef9 to your computer and use it in GitHub Desktop.
Save maxdeepfield/fc1a53e6f71bdbbeaef9 to your computer and use it in GitHub Desktop.
// converts HH:ii time to seconds from midnight
var timeToSeconds = function(time){
if (time.length != 5) {
return false;
}
var h = Number(time.split(':')[0]);
var m = Number(time.split(':')[1]);
if (isNaN(h) || isNaN(m)) {
return false;
}
if (h < 0 || h > 23) {
return false;
}
if (m < 0 || m > 59) {
return false;
}
return h*60*60+m*60;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment