dateDisplay method
Display date like Jan 15, 1945 (or Jan 15th, 1945 with
showDayOrdinal). When showCurrentYear is false, the year is omitted for
dates in the current year (determined against now, injectable for tests).
Named skeletons (yMMMd / MMMMd / ...) reorder per locale; the ordinal
path does not, because English ordinals lock English month-day order.
monthFormat == 'MMMM' selects the full month name; any other value uses
the abbreviated skeleton.
Example:
DateTime(1945, 1, 15).dateDisplay(locale: 'en_US'); // 'Jan 15, 1945'
Audited: 2026-06-12 11:26 EDT
Implementation
String dateDisplay({
String monthFormat = 'MMM',
bool showDayOrdinal = false,
bool showCurrentYear = true,
String? locale,
DateTime? now,
}) {
final DateTime today = now ?? DateTime.now();
final bool showYear = showCurrentYear || year != today.year;
// English-ordinal path keeps fixed month-day order; it cannot localize.
if (showDayOrdinal) {
return _ordinalDateDisplay(this, monthFormat, locale, showYear);
}
return _skeletonDateDisplay(this, monthFormat, locale, showYear);
}