toDifferenceAgo method

String toDifferenceAgo()

Returns text representation of a difference with DateTime.now indicating how long ago this DateTime happened compared to DateTime.now.

Implementation

String toDifferenceAgo() {
  DateTime local = isUtc ? toLocal() : this;
  Duration diff = DateTime.now().difference(local);

  return 'label_ago'.l10nfmt({
    'years': diff.inDays ~/ 365,
    'months': diff.inDays ~/ 30,
    'weeks': diff.inDays ~/ 7,
    'days': diff.inDays,
    'hours': diff.inHours,
    'minutes': diff.inMinutes,
  });
}