timeAgo property

String get timeAgo

Returns a relative time description like:

  • just now (if < 60 seconds),
  • x min ago (if < 60 minutes),
  • x hours ago (if < 24 hours),
  • otherwise, it falls back to formattedDate.

Example:

DateTime.now().subtract(Duration(minutes: 5)).timeAgo; // "5 min ago"

Implementation

String get timeAgo {
  final now = DateTime.now();
  final difference = now.difference(this);

  if (difference.inSeconds < 60) return 'just now';
  if (difference.inMinutes < 60) return '${difference.inMinutes} min ago';
  if (difference.inHours < 24) return '${difference.inHours} hours ago';

  return formattedDate;
}