Created
June 19, 2015 12:59
-
-
Save soniakeys/ea722017e19b29402216 to your computer and use it in GitHub Desktop.
ISO 8601 Durations
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 ( | |
decPart = `\d*[.,]\d*` | |
intPart = `\d+` | |
decS = `(?:(?P<decS>` + decPart + `)S)` | |
intS = `(?:(?P<intS>` + intPart + `)S)?` | |
sPat = `(?:` + decS + `|` + intS + `)` | |
decMin = `(?:(?P<decMin>` + decPart + `)M)` | |
intMin = `(?:(?P<intMin>` + intPart + `)M)?` | |
minPat = `(?:` + decMin + `|(?:` + intMin + sPat + `))` | |
decH = `(?:(?P<decH>` + decPart + `)H)` | |
intH = `(?:(?P<intH>` + intPart + `)H)?` | |
hPat = `(?:T(?:` + decH + `|(?:` + intH + minPat + `)))?` | |
decD = `(?:(?P<decD>` + decPart + `)D)` | |
intD = `(?:(?P<intD>` + intPart + `)D)?` | |
dPat = `(?:` + decD + `|(?:` + intD + hPat + `))` | |
decW = `(?:(?P<decW>` + decPart + `)W)` | |
intW = `(?:(?P<intW>` + intPart + `)W)?` | |
wPat = `(?:` + decW + `|(?:` + intW + dPat + `))` | |
decMon = `(?:(?P<decMon>` + decPart + `)M)` | |
intMon = `(?:(?P<intMon>` + intPart + `)M)?` | |
monPat = `(?:` + decMon + `|(?:` + intMon + wPat + `))` | |
decY = `(?:(?P<decY>` + decPart + `)Y)` | |
intY = `(?:(?P<intY>` + intPart + `)Y)?` | |
yPat = `(?:` + decY + `|(?:` + intY + monPat + `))` | |
durPat = `^P` + yPat + `$` | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
some experimentation