fromPrecise method

String fromPrecise(
  1. DateTime anchor, {
  2. bool round = true,
  3. bool omitZeros = true,
  4. bool includeWeeks = true,
  5. Abbreviation form = Abbreviation.none,
  6. String? delimiter,
  7. DurationFormat format = DurationFormat.auto,
  8. bool dropPrefixOrSuffix = false,
})

This will return precise durations. For imprecise durations, use from()

e.g.:

  • 2 minutes 39 seconds ago
  • in 2m 39s

Params:

  • 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

String fromPrecise(
  DateTime anchor, {
  bool round = true,
  bool omitZeros = true,
  bool includeWeeks = true,
  Abbreviation form = Abbreviation.none,
  String? delimiter,
  DurationFormat format = DurationFormat.auto,
  bool dropPrefixOrSuffix = false,
}) {
  final Duration delta = difference(anchor);

  return localization.duration(
    delta,
    round: round,
    omitZeros: omitZeros,
    includeWeeks: includeWeeks,
    form: form,
    delimiter: delimiter,
    format: format,
  );
}