Skip to content

Instantly share code, notes, and snippets.

@alexilyaev
Created December 6, 2018 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexilyaev/4f92dde3e5443f79f5d65513ec7849e2 to your computer and use it in GitHub Desktop.
Save alexilyaev/4f92dde3e5443f79f5d65513ec7849e2 to your computer and use it in GitHub Desktop.
Alfred Worflow - Time To Decimal
/**
* Convert a time string to a decimal value
*
* @param {string} argv e.g. 142h13m, 142 h 13 min
*/
function run(argv) {
const query = argv[0];
const [, hours, minutes] = query.match(/\s*(?:(\d+)\s*h)?\s*(?:(\d+)\s*m)?/)
let decimal = 0;
if (hours) {
decimal += Number(hours);
}
if (minutes) {
decimal += Number(minutes) / 60;
}
const result = decimal ? decimal.toFixed(2) : 0;
return `{
"items": [
{
"title": "Decimal value:",
"subtitle": ${result},
"arg": ${result}
}
]
}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment