duration static method
String
duration(
- Duration duration, {
- MomentLocalization? localization,
- bool round = true,
- bool omitZeros = true,
- bool includeWeeks = false,
- Abbreviation form = Abbreviation.none,
- String? delimiter,
- DurationFormat format = DurationFormat.auto,
- bool dropPrefixOrSuffix = false,
Returns precise duration for duration
in localization
e.g.:
- 2 minutes 39 seconds
- 2m39s
Params:
localization
- when null, defaults toMoment.defaultLocalization
(see setGlobalLocalization)format
- format to display the duration. For example, when set toDurationFormat.md
, will result to "3 months 2 days"delimiter
- string to join duration when there are more than one. Defaults to space. For example,form
- Unit string form. For example, minute would look like "18 minutes", "18 min", "18m" in full, mid, short forms, respectively.round
- rounds the smallest unit if true, or truncates. Defaults to true.omitZeros
- unit will be omitted if equal to zero. For example,DurationFormat.md
may return "3 months", but not "3 months 0 days"includeWeeks
- Whetherweek
should be treated as duration unit. Only applicable when using DurationFormat.autodropPrefixOrSuffix
- Whether to drop suffix/prefix. For example, "3h 2m ago" => "3h 2m", "in 7 days" => "7 days"
Implementation
static String duration(
Duration duration, {
MomentLocalization? localization,
bool round = true,
bool omitZeros = true,
bool includeWeeks = false,
Abbreviation form = Abbreviation.none,
String? delimiter,
DurationFormat format = DurationFormat.auto,
bool dropPrefixOrSuffix = false,
}) =>
duration.toDurationString(
localization: localization ?? Moment.defaultLocalization,
round: round,
omitZeros: omitZeros,
includeWeeks: includeWeeks,
form: form,
format: format,
delimiter: delimiter,
dropPrefixOrSuffix: dropPrefixOrSuffix,
);