datetime/date_time_intl_display_extensions library
Locale-correct DateTime display via intl skeletons — the one opt-in
module in lib/datetime/ that pulls the intl dependency.
The rest of this package deliberately avoids intl (see
date_format_preset_utils.dart, which formats manually with injectable
names in a FIXED layout). These extensions exist because a fixed layout
cannot reorder components per locale: intl skeletons (yMMMd, MMMEd,
jm, ...) render "Jan 15, 1945" for en_US but "15 janv. 1945" for fr_FR
and "1945年1月15日" for ja_JP, AND auto-detect each locale's clock
convention (12h AM/PM vs 24h). None of the logic is domain-specific; it
operates on any DateTime.
Callers that format non-English locales MUST call
initializeDateFormatting() (from package:intl/date_symbol_data_local.dart)
once per process before invoking these methods — intl throws for an
unloaded locale, and every method here catches that and degrades rather
than propagating.
Split across part files purely to honor the project's 200-line file cap.
The display methods are grouped into three extensions on DateTime —
DateTimeIntlDisplayExtensions (offset + explicit-pattern formatting),
DateTimeIntlDateDisplayExtensions (calendar-date renderings), and
DateTimeIntlTimeDisplayExtensions (clock renderings). All of it is ONE
library, so the private helpers stay shared across the parts and every
method is still called on a plain DateTime exactly as before; the split
is invisible to callers, who import this file via the barrel.
Enums
- UtcTimeDisplayEnum
-
Clock-display presets for
DateTimeIntlDisplayExtensions.utcTimeDisplay.
Extensions
- DateTimeIntlDateDisplayExtensions on DateTime
-
Locale-correct calendar-date renderings (no clock).
localeis an intl locale string (e.g.'en_US','fr_FR');nulllets intl use its default. - DateTimeIntlDisplayExtensions on DateTime
-
Locale-correct
DateTimedisplay: UTC offset and explicit-pattern formatting.localethroughout is an intl locale string (e.g.'en_US','fr_FR');nulllets intl use its default. - DateTimeIntlTimeDisplayExtensions on DateTime
-
Locale-correct clock renderings.
localeis an intl locale string (e.g.'en_US','fr_FR');nulllets intl use its default.
Functions
-
formatUtcOffset(
Duration offset, {bool verbose = false}) → String -
Formats a UTC offset Duration as
UTC+H:MM/UTC-H/UTC±0.