Created
June 9, 2016 06:39
-
-
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)
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
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