makeDisplayDate method
Display date with weekday like Thu, Jul 21, 2020 (locale-ordered).
Returns null on failure (unloaded locale) so callers can fall back. The
year is shown only when showYear is true AND either showCurrentYear is
set or the date is not in the current year (against now) AND year > 0
— the year > 0 guard suppresses the year for the BCE/placeholder dates
DateTime(0) produces, which would otherwise render a misleading "1".
showWeekday toggles the leading weekday.
Audited: 2026-06-12 11:26 EDT
Implementation
String? makeDisplayDate({
bool showYear = true,
bool showCurrentYear = false,
bool showWeekday = true,
String? locale,
DateTime? now,
}) {
try {
final DateTime today = now ?? DateTime.now();
// Combine all three year-suppression rules; year > 0 blocks year-zero noise.
final bool renderYear = showYear && (showCurrentYear || year != today.year) && year > 0;
return _displayDateFor(this, renderYear, showWeekday, locale);
// Unloaded/malformed locale must degrade to null, never crash a UI.
// ignore: require_catch_logging -- display contract: never throw, callers fall back on null
} on Object {
return null;
}
}