I would like to expand my locale-aware date/time formatting library (elm-cldr) to support the more granular formatting options that would be required for it to support more use cases, e.g. Fluent.
My current plan is to add a new module Cldr.Format.Options:
module Cldr.Format.Options exposing (..)
type alias DateTimeOptions =
{ era : Maybe TextOption
, year : Maybe NumberOption
, month : Maybe NumberOrTextOption
, day : Maybe NumberOption
, weekday : Maybe TextOption
, period : Maybe TextOption
, hour : Maybe NumberOption
, minute : Maybe NumberOption
, second : Maybe NumberOption
, fractionalSecondDigits : Maybe FractionalDigits
, zone : Maybe NameOption
, hour12 : Maybe HourType
}
defaultDateTimeOptions : DateTimeOptions
type alias DateOptions =
{ era : Maybe TextOption
, year : Maybe NumberOption
, month : Maybe NumberOrTextOption
, day : Maybe NumberOption
, weekday : Maybe TextOption
}
defaultDateOptions : DateOptions
type TextOption
= Short
| Long
| Narrow
type NumberOption
= Numeric
| TwoDigit
type NumberOrTextOption
= Text TextOption
| Number NumberOption
type FractionalDigits
= One
| Two
| Three
type NameOption
= ShortName
| LongName
type HourType
= Hour12
| Hour24
The FormatType in Cldr.Format.DateTime module would then be updated:
module Cldr.Format.DateTime exposing (..)
type FormatType
= DateOnly Length
| TimeOnly Length
| DateAndTime { date : Length, time : Length }
| WithOptions DateTimeOptions
The Cldr.Format.Date module would also gain a FormatType and the format function would change signature to use it:
module Cldr.Format.Date exposing (..)
type FormatType
= WithLength Length
| WithOptions DateOptions
format : FormatType -> Locale -> Date -> String
I am interested in feedback generally, but specifically in thoughts about these questions:
- Should the
Cldr.Format.Optionsmodule havesetXhelper functions, e.g.setMonthNumber : NumberOption -> DatePlusOptions a -> DatePlusOptions a? - Is the
Cldr.Format.Date.formatrefactor ok? It would turnformat Short myLocale dateintoformat (WithLength Short) myLocale date. The alternative would be to add a second format function, likeformatWithOptions : DateOptions -> Locale -> Date -> String, which is less consistent withCldr.Format.DateTime.
Many thanks to everyone who has already provided feedback and interest in this project!