duration static method

String duration(
  1. Duration duration, {
  2. MomentLocalization? localization,
  3. bool round = true,
  4. bool omitZeros = true,
  5. bool includeWeeks = false,
  6. Abbreviation form = Abbreviation.none,
  7. String? delimiter,
  8. DurationFormat format = DurationFormat.auto,
  9. bool dropPrefixOrSuffix = false,
})

Returns precise duration for duration in localization

e.g.:

  • 2 minutes 39 seconds
  • 2m39s

Params:

  • localization - when null, defaults to Moment.defaultLocalization (see setGlobalLocalization)
  • format - format to display the duration. For example, when set to DurationFormat.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 - Whether week should be treated as duration unit. Only applicable when using DurationFormat.auto
  • dropPrefixOrSuffix - 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,
    );