fromNowPrecise method

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

Example when using LocalizationEnUs:

If this is yesterday, will result "1 day ago"

If this is tomorrow, will result "in 1 day"

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 fromNowPrecise({
  bool round = true,
  bool omitZeros = true,
  bool includeWeeks = true,
  Abbreviation form = Abbreviation.none,
  String? delimiter,
  DurationFormat format = DurationFormat.auto,
  bool dropPrefixOrSuffix = false,
}) =>
    fromPrecise(
      DateTimeConstructors.nowWithTimezone(isUtc),
      round: round,
      omitZeros: omitZeros,
      includeWeeks: includeWeeks,
      form: form,
      delimiter: delimiter,
      format: format,
      dropPrefixOrSuffix: dropPrefixOrSuffix,
    );