Skip to content

Instantly share code, notes, and snippets.

@mfjohansson
Last active December 18, 2015 07:48
Show Gist options
  • Save mfjohansson/5748839 to your computer and use it in GitHub Desktop.
Save mfjohansson/5748839 to your computer and use it in GitHub Desktop.
Parse time from a string, result in minutes. E.g.: `5h 30 m` `1d2h45m` `2 hours, 45 mins`
function parseTime(inp) {
return eval(inp.replace(/(secs|second|seconds)/gi, "s").replace(/(mins|minute|minutes)/gi, "m").replace(/(hour|hours)/gi, "h").replace(/(day|days)/gi, "d").replace(/(week|weeks)/gi, "w").replace(/[^0-9hdwms]/gi, "").replace(/([a-z])/gi, "$1+").replace("h", "*60").replace("d", "*60*8").replace("w", "*60*8*5").replace("m", "*1").replace("s", "/60") + "-0");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment