Intl.DateTimeFormat

A library for formatting dates in a language sensitve way. This module binds to Intl.DateTimeFormat.

Create

type DateTimeFormat

A DateTimeFormat object, for formatting dates in a language sensitive way.

fromLocale
:
Intl.Locale.Locale -> Intl.DateTimeFormat.DateTimeFormat

Create a DateTimeFormat using rules from the specified language

format (fromLocale "pt-BR") christmas
-- "25/12/2016"
fromOptions
:
Intl.DateTimeFormat.Options -> Intl.DateTimeFormat.DateTimeFormat

Create a DateTimeFormat using rules from the language and other options.

let
  formatTime = fromOptions
    { defaults |
    , locale = Locale.de
    , hour = NumericNumber
    , minute = TwoDigitNumber
    }
    |> format
in
  formatTime elevenPM -- 23:00

Formatting Dates

format
:
Intl.DateTimeFormat.DateTimeFormat -> Date.Date -> String

Format a Date according to the rules of the DateTimeFormat.

format (fromLocale Locale.en) Date.now

Support and options

Not all environments will support all languages and options. These functions help determine what is supported, and what options a particular DateTimeFormat will use.

type NameStyle
= NarrowName
| ShortName
| LongName
| OmitName

Style options for the date parts that can be names.

type NumberStyle
= NumericNumber
| TwoDigitNumber
| OmitNumber

Style options for the date parts that can be numbers.

defaults
:
Intl.DateTimeFormat.Options

Returns the default options. This is helpful if you only care to change a few options. If all the date time parts are left ommitted, then year, month, and day will be assumed numeric.

options : Options
options =
  { defaults | weekday = ShortName }
resolvedOptions
:
Intl.DateTimeFormat.DateTimeFormat -> Intl.DateTimeFormat.Options

Returns the locale and formatting options computed when the DateTimeFormat was created.

if (resolvedOptions dateTimeFormat).hour12 then
  "AM/PM"
else
  "Military Time"
supportedLocalesOf
:
List Intl.Locale.Locale -> List Intl.Locale.Locale

Returns a list from the provided languages that are supported without having to fall back to the runtime's default language.

case fromLanguageTag "tlh" of
  Just klingon ->
    if isEmpty (supportedLocalesOf [ klingon ]) then
      "I can't sort Klingon text"
    else
      "Make it so, Number One"
  Nothing ->
    "Khaaaaan!"
Basic information
README
Browse source on Github
Elm version: 0.17.1 <= v < 0.18.0
Contains Native Module(s)
Modules
Intl.Collator Intl.Currency
Intl.DateTimeFormat
Intl.Locale Intl.NumberFormat Intl.TimeZone
Versions
1.0.0
Dependencies