DurationClockFormatExtensions extension
Clock- and word-style formatters for Duration.
These complement the existing top-level formatDuration(Duration d, ...)
in duration_format_utils.dart, which rolls up to days and uses
space-separated short labels. The members here deliberately differ:
- displayTime renders a stopwatch/media
HH:MM:SS.mmmclock string and never rolls hours into days (a 25-hour duration shows as25:...). - formatDuration renders a comma-joined human list of non-zero units down
to microseconds, returning
'Instantaneous'for Duration.zero. - reverse returns the sign-negated duration.
All operations are pure integer arithmetic on Duration fields — no locale, no wall-clock date, so there are no DST / timezone / leap-year concerns (those apply to DateTime, not Duration).
- on
Methods
-
displayTime(
{bool showHours = true}) → String -
Available on Duration, provided by the DurationClockFormatExtensions extension
Formats this duration as a zero-padded stopwatch clock string. -
formatDuration(
{bool showLeadingZeros = false, bool shortForm = true}) → String? -
Available on Duration, provided by the DurationClockFormatExtensions extension
Formats this duration as a comma-joined human-readable list of units. -
reverse(
) → Duration -
Available on Duration, provided by the DurationClockFormatExtensions extension
Returns the sign-negated duration (positive <-> negative).