Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update readme/docs to de-emphasise usage of string formats #22

Open
garyb opened this issue Jul 6, 2017 · 5 comments · May be fixed by #27
Open

Update readme/docs to de-emphasise usage of string formats #22

garyb opened this issue Jul 6, 2017 · 5 comments · May be fixed by #27
Labels
type: enhancement A new feature or addition.

Comments

@garyb
Copy link
Member

garyb commented Jul 6, 2017

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.

@garyb
Copy link
Member Author

garyb commented Jul 6, 2017

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.

@garyb garyb added the type: enhancement A new feature or addition. label Jul 6, 2017
@garyb
Copy link
Member Author

garyb commented Jul 14, 2017

@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.

@safareli
Copy link
Contributor

safareli commented Jul 14, 2017

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)

@safareli
Copy link
Contributor

Here are some constraints I had for DatePicker formats: (time, date, datetime)

p.s. looks like i have missed that if you use DayOfMonth there must be month component in format too

@safareli
Copy link
Contributor

If we merge #26 then we would not be able to build datetime parser using date and time parsers because of "day shift".
but we can still make time and date modules and derive validDate and validTime formats using typeclass mechanisms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A new feature or addition.
Development

Successfully merging a pull request may close this issue.

2 participants