Update readme/docs to de-emphasise usage of string formats
Opened this issue · 5 comments
We and I'm sure others have a lot of code that looks like this sort of thing at the moment:
timeFormat = unsafePartial fromRight $ parseFormatString "HH:mm:ss"Which is actually quite silly, when it's actually easier, safer, and generally better all round to just construct the format directly:
timeFormat = Hours24 : MinutesTwoDigits : SecondsTwoDigits : Nil
-- or
timeFormat' = L.fromFoldable [Hours24, MinutesTwoDigits, SecondsTwoDigits]😆
As another advantage of that is Hours24 is better self-documentation than remembering "HH" vs "hh" for Hours24 vs Hours12 too, etc.
Not saying we shouldn't support the string formats - they do have their uses, just not for formatters that are statically defined in PureScript code.
@safareli pointed out that some formats are invalid (as they'd parse ambiguously)
We may do something like this: https://gist.github.com/garyb/1c4fda54c630e59e609c1f04058e5ac8 so we can validate formats at the type level.
I think we would need to split formats, like have separate DateFormat and TimeFormat and use them in DateTimeFormat:
newtype DateFormat = DateFormat (List DateCommand)
data DateCommand
= YearFull
| YearTwoDigits
| YearAbsolute
| Placeholder String
...
newtype TimeFormat = TimeFormat (List TimeCommand)
data TimeCommand
= Hours24
| Hours12
| Meridiem
| Placeholder String
...
data DateTimeCommand
= Date DateFormat
| Time TimeFormat
| Placeholder String
newtype DateTimeFormat = DateTimeFormat (List DateTimeCommand)