This Elm packages provides locale-aware formatting of Date
s and time
s. Formats for each locale are taken from the Unicode CLDR Project. It is intended to be accessible to developers who are familiar with the JS Intl
API.
elm install enkidatron/elm-cldr
- Parse a
Locale
from a locale identifier string to store in yourModel
:fromString
- Or choose a hardcoded date, such as
en
- Format a
Date
fromjustinmimbs/date
:Format.Date.format
- Format a
Posix
fromelm/time
:Format.DateTime.format
See examples
directory for full examples.
import Cldr.Format.Date
import Cldr.Format.Length exposing (Length(..))
import Cldr.Locale exposing (Locale, root)
import Date exposing (Date)
import Time
localeStringFromFlags : String
localeStringFromFlags = "ru"
locale : Maybe Locale
locale =
Cldr.Locale.fromString
Cldr.Locale.allLocales
localeStringFromFlags
date : Date
date = Date.fromCalendarDate 2022 Time.Jan 10
formatted : String
formatted =
Cldr.Format.Date.format
(Cldr.Format.Date.WithLength Short)
(Maybe.withDefault root locale)
date
The Cldr.Locale
file is automatically generated from the CLDR JSON. In order to keep this library repo clean, the code for that generation can be found at enkidatron/elm-cldr-generator
- 2.1.0: release-41
- 1.0.0: release-40