An empty duration. All units are set to 0.
There are three lengths that can be used when formatting a duration.
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"These are the different options for which units to display when formatting a duration.
Standard only displays units that have a non-zero value.
TrimLargest starts from the largest (years) and removes units until it finds a non-zero value or there is only one value left.
TrimSmallest starts from the smallest (milliseconds) and removes units until it finds a non-zero value or there is only one value left.
TrimLargestAndSmallest does TrimLargest and then TrimSmallest.
IncludeUnitsIfZero includes all units that are not zero, and also all units marked as True in the UnitsToDisplay record.If you want to display specific units in your durationFormats a Duration using the specified UnitDisplayOptions, Length, and Locale
import Cldr.Locale exposing (en)
formatWithOptions Standard Long en { zero | hours = 1, minutes = 30}
--> "1 hour, 30 minutes"
formatWithOptions TrimLargest Long en { zero | hours = 1, minutes = 30}
--> "1 hour, 30 minutes, 0 seconds, 0 milliseconds"
formatWithOptions TrimLargestAndSmallest Long en zero
--> "0 milliseconds"
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 intoIntl.DurationFormat. The browser'sIntl.DurationFormatcan 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.