purescript-contrib / purescript-formatters

Formatting and printing for numeric and date/time/interval values
Apache License 2.0
41 stars 29 forks source link

RFC: Seperate `Date` and `Time` format functions #71

Open hexagonal-sun opened 3 years ago

hexagonal-sun commented 3 years ago

Hi,

It would be nice if functions for formatting Date and Time types exist. Currently, if one wants to format a Date, a dummy Time value needs to be be created to convert to a DateTime for formatting; likewise for the Time type.

I'm not exactly sure what the best way to do this would be. Maybe:

  data PlacholderFormatterCommand = Placeholder String

  data DateFormatterCommand
    = YearFull
    | YearTwoDigits
    | YearAbsolute
    | MonthFull
      [...]
    | PlaceholderFormatterCommand

  data TimeFormatterCommand
    = [...]
    | PlaceholderFormatterCommand

  data DateTimeFormatterCommand
    = DateFormatterCommand
    | TimeFormatterCommand

The main issue I see with this approach are FormatterCommands that are applicable to both Dates and Times, namely Placeholder and UnixTimestamp. Maybe there is a more elegant solution involving type classes?

garyb commented 3 years ago

Maybe there is a more elegant solution involving type classes?

I don't think there is really, it's still going to need to be reified into types at some point. Constructing the formats could perhaps be made easier using some Inject style classes on top, but I think it'd be fine without too probably.

wclr commented 3 years ago

Would be nice to have ready-to-go formatters for Date and Time types.

CarstenKoenig commented 1 year ago

sorry - I did link the wrong issue - please ignore the last message here :(