Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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