format static method
Formats provided date
to a fuzzy time like 'a moment ago'
- If
locale
is passed will look for message for that locale, if you want to add or override locales use setLocaleMessages. Defaults to 'en' - If
now
is passed this will be the point of reference for calculating the elapsed time. Defaults to DateTime.now() - If
max
is passed, format will only happen between that duration and beyond that simple date format will be shown. To avoid format limits, Passnull
. Defaults to14
days - If
short
is passed, format will use the short version of locale. i.e. foren_short
locale 5 minute ago will format as5m
- If
withFuture
is passed, format will use the From prefix, ie. a date 5 minutes from now in 'en' locale will display as "5 minutes from now"
Implementation
static String format(
DateTime date, {
String? locale,
DateTime? now,
Duration? max = const Duration(days: 14),
bool short = false,
bool withFuture = false,
}) =>
max != null && (now ?? Date.now).difference(date) > max
? short
? date.formatMMMdY
: date.formatMMMMdY
: timeago.format(
date,
locale: (locale ?? _default).post("_short", doIf: short),
clock: now,
allowFromNow: withFuture,
);