Created
December 6, 2018 11:09
-
-
Save alexilyaev/4f92dde3e5443f79f5d65513ec7849e2 to your computer and use it in GitHub Desktop.
Alfred Worflow - Time To Decimal
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
/** | |
* 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