Skip to content

Instantly share code, notes, and snippets.

@sudodoki
Created June 9, 2016 06:39
Show Gist options
  • Save sudodoki/7e6dd07d9e296e919bc2c8bedb2a403c to your computer and use it in GitHub Desktop.
Save sudodoki/7e6dd07d9e296e919bc2c8bedb2a403c to your computer and use it in GitHub Desktop.
Youtrack hour/day/week notation converter to hours. Assumption is you never have more than one digit (for regexp split to work correctly)
const DURATION = {
"d": 6,
"w": "30"
};
[
"?",
"2h",
"2h",
"1d",
"1w2d",
"1w2h"
].filter(i => i !== "?")
.reduce((memo, item) => {
return memo.concat(item.split(/(?=\d+)/))
},[])
.map(item => {
const [number, period] = item.split(/(?=\w)/)
return (DURATION[period] || 1) * number
})
.reduce((s, i) => s + i, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment