timeAgoFrom static method
String
timeAgoFrom(
- String? dateTime, {
- DateTime? now,
- bool assumeUtc = false,
- int justNowSeconds = 10,
- TimeAgoLabels? labels,
timeAgo for a datetime string (ISO-8601 or yyyy-MM-dd HH:mm:ss).
Returns '' for null / blank / unparseable input instead of throwing —
safe to drop straight into a widget from an API/DB field.
Implementation
static String timeAgoFrom(
String? dateTime, {
DateTime? now,
bool assumeUtc = false,
int justNowSeconds = 10,
TimeAgoLabels? labels,
}) {
if (dateTime == null || dateTime.trim().isEmpty) return '';
final d = DateTime.tryParse(dateTime.trim().replaceFirst(' ', 'T'));
if (d == null) return '';
return timeAgo(d,
now: now,
assumeUtc: assumeUtc,
justNowSeconds: justNowSeconds,
labels: labels);
}