friendlyPastTimeFormat function
Formats a past time as a coarse, human-friendly relative-time
phrase like "2 hours ago" or "just now", measured against now
which defaults to the current time.
Times more than 7 days in the past are formatted as an absolute
timestamp instead, like "2026-07-23 09:15:05" — in the local time
zone, or in UTC if inUtc is set.
Implementation
String friendlyPastTimeFormat(
final DateTime time, {
final bool inUtc = false,
final DateTime? now,
}) {
final elapsed = (now ?? DateTime.now()).difference(time);
if (elapsed > _relativeTimeLimit) {
return time.toTzString(inUtc, _numTimestampChars);
}
return friendlyAgoFormat(elapsed);
}