enkidatron/elm-cldr/3.1.0

NOTE: the latest version is 3.2.1

Cldr.Format.Duration

Duration Formatting

type alias Duration =
{ years : Int
, months : Int
, weeks : Int
, days : Int
, hours : Int
, minutes : Int
, seconds : Int
, milliseconds : Int
}

A duration that can be formatted.

To be consistent with Intl.DurationFormat, years are the largest units. This only accepts integers for the various units, which is consistent with passing an object into Intl.DurationFormat. The browser's Intl.DurationFormat can also accept an ISO8601 duration string directly (which can have decimals in the numbers), although JS has the "luxury" of simply throwing an error if you provide a combination of decimals that it doesn't know how to handle. To use this library, you have to turn "1.5 hours" into {zero | hours = 1, minutes = 30} yourself.

type Length
= Narrow
| Short
| Long

There are three lengths that can be used when formatting a duration.

format : Length -> Locale -> Duration -> String

Formats a Duration using the specified Length and Locale

import Cldr.Locale exposing (en)


format Long en { zero | hours = 1, minutes = 30}
--> "1 hour, 30 minutes"
zero : Duration

An empty duration. All units are set to 0.