Skip to content

Commit 6159472

Browse files
authored
Interval formatters (#17)
* WIP Interval formatters * fix number parser in duration * update Data.Interval * refactor Duration parser at this point we need to upgrade to [email protected] * add is valid iso duration test * add interval parsers * extract parsers in seperate module * move 'digit' to parser.number * remove State from unformatParser * use weaker hoistParserT * use ParserT instead of Parser * use more oneOfAs * export unformatParser from DateTime; fix interval related parser tests * un-export HasDuration for Duration (live one for IsoDuration only) * add tests for all variation of valid Recurringinterval * add Eq and Show instance for datetime.FormatterF * make formatterF parser error a bit more usable * include error position in error string of parser result * use ps-spec and refactor tests to more generative style * remove some outdated commets * fix let usage * remove 'Q', 'X', 'W' from restricted chars of placeholder * fix failing test * make Number.Formatter newtype reason is that we need to use it in tests where values need to implement Eq and Show * refactor numeralTests * refactor tests * merge Parser/DateTime back into DateTime * fix warning * update ps-parser * add invalid interval/durations; fix parsing of PT1M * update ps-spec * update ps-parser * remove Has{Duration,Date} class; add EOF to runP we want to fully consume input when parsers are executed * remove unused ps-debug * add format function; refactor interval tests * use forAll for testing * refactor padDoubleDigit * add resoliutions * fix resolution * add space to formatterFShow * use <?> * refactor digit parsing * remove unneeded range checks the range check is not relevent then we have know exact length of digits and range is min and max for the number * reorder parseInt validations so that we don't need parens * add noValidate * refactor datetime parser * don't use MonadState with P.ParserT * use readFloat in parseFractional * refactor parseMaybeInteger * refactor unEither * refactor foldFoldableMaybe * fix where indentation * more where indentation * add Newtype instance for Number.Formatter; derive Eq * derive Eq for DateTime.FormatterF * derive Functor for DateTime.FormatterF * replace -> with → * replace :: with ∷ * replace <- with ← * replace => with ⇒ * replace forall with ∀ * replace more => with ⇒ * use monoid instance of ReaderT in parser validators * change Formatter to List FormatterCommands * unflip * remove unused * fix parsing formats like 'HHmm' (without seperators) * fix build * fix 'SS' and 'S' parsing * export printFormatterCommand * update ps-datetime * remove unused * use published version of purescript-lists * update ps-transformers * use unsafePartial instead of unsafePartialBecause * update datetime * fix number test * remove some old todos * use released version of ps-datetime * fix first char case in errors. * add todo on negative numbers * fix lifts * fix arrows and forall * fix double let * use lift2 and sort imports * remove outdated anotation * let on next line * rename notEmpty to failIfEmpty
1 parent 39816bd commit 6159472

File tree

15 files changed

+1049
-669
lines changed

15 files changed

+1049
-669
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ Formatter has following properties
2222

2323
Number will be padded with zeros to have at least this number of leading zeros.
2424
This doesn't restrict number to have more digits then leading zeros in format string.
25-
+ `0000.0` will show 4 digits: `12 -> "0012.0"`, `1234 -> "1234.0"`
26-
+ `00.0` will show only 2 digits : `12 -> "12.0"`, `1234 -> "1234.0"`
25+
+ `0000.0` will show 4 digits: `12 "0012.0"`, `1234 "1234.0"`
26+
+ `00.0` will show only 2 digits : `12 "12.0"`, `1234 "1234.0"`
2727

2828
Number of digits after dot is set by number of trailing zeros (note the rounding)
29-
+ `0.000` will show 3 digits: `0.12345 -> "0.123"`, `12.98765 -> "12.988"`
30-
+ `0.0` will show only 1 digit: `0.12345 -> "0.1"`, `12.98765 -> "13.0"`
29+
+ `0.000` will show 3 digits: `0.12345 "0.123"`, `12.98765 "12.988"`
30+
+ `0.0` will show only 1 digit: `0.12345 "0.1"`, `12.98765 "13.0"`
3131

3232
If number is lesser then zero `-` is always printed. Otherwise you could specify `+` in format string
33-
+ `+0`: `12.0 -> "+12"`, `-34.8 -> "-35"`
34-
+ `0`: `12.0 -> "12"`, `-34.8 -> "-35"`
33+
+ `+0`: `12.0 "+12"`, `-34.8 "-35"`
34+
+ `0`: `12.0 "12"`, `-34.8 "-35"`
3535

3636
Thousands separator is specified as `,0` please note that this `0` isn't counted as leading.
37-
+ `00,0`: `1234567890 -> "1,234,567,890.0", `1 -> "1.0"`
37+
+ `00,0`: `1234567890 "1,234,567,890.0", `1 "1.0"`
3838

3939
For abbreviation one could use `a` flag. In general it tries to find the closest power of thousand and
4040
then use formatter to result of division of input number and that power.
41-
+ `0a`: `1234567 -> "1M"`, `1 -> "1"`
41+
+ `0a`: `1234567 "1M"`, `1 "1"`
4242

4343
## Date/Time formatters
4444

bower.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,20 @@
1717
],
1818
"dependencies": {
1919
"purescript-prelude": "^3.0.0",
20-
"purescript-parsing": "^4.0.0",
20+
"purescript-parsing": "^4.2.1",
2121
"purescript-fixed-points": "^4.0.0",
22-
"purescript-datetime": "^3.0.0"
22+
"purescript-datetime": "^v3.3.0",
23+
"purescript-transformers": "^3.4.0",
24+
"purescript-lists": "^4.3.0",
25+
"purescript-generics-rep": "^5.0.0"
2326
},
2427
"devDependencies": {
2528
"purescript-aff": "^3.0.0",
2629
"purescript-console": "^3.0.0",
2730
"purescript-psci-support": "^3.0.0",
28-
"purescript-debug": "^3.0.0"
31+
"purescript-spec": "^0.14.0"
32+
},
33+
"resolutions": {
34+
"purescript-datetime": "interval"
2935
}
3036
}

0 commit comments

Comments
 (0)