HumanizedDuration extension

A powerful extension on Duration offering formatting, arithmetic operations, and utility functions.

Features include:

  • Human-readable string formatting (e.g. toHumanizedString, toWordString, toRelativeString)
  • Mathematical operations (*, /) and bound checking (clamp, abs)
  • Convenient component accessors (hoursPart, totalMinutes)
  • Progress percentages and rounding calculations
on

Properties

abs Duration

Available on Duration, provided by the HumanizedDuration extension

Returns the absolute (non-negative) value of this duration.
no setter
hoursPart int

Available on Duration, provided by the HumanizedDuration extension

Returns the absolute hours component of the duration.
no setter
isNegative bool

Available on Duration, provided by the HumanizedDuration extension

Returns true if this duration is less than zero.
no setter
isPositive bool

Available on Duration, provided by the HumanizedDuration extension

Returns true if this duration is greater than zero.
no setter
isZero bool

Available on Duration, provided by the HumanizedDuration extension

Returns true if this duration is exactly zero.
no setter
millisecondsPart int

Available on Duration, provided by the HumanizedDuration extension

Returns the absolute milliseconds component of the duration (0-999).
no setter
minutesPart int

Available on Duration, provided by the HumanizedDuration extension

Returns the absolute minutes component of the duration (0-59).
no setter
secondsPart int

Available on Duration, provided by the HumanizedDuration extension

Returns the absolute seconds component of the duration (0-59).
no setter
totalDays double

Available on Duration, provided by the HumanizedDuration extension

Returns the total duration in floating-point days.
no setter
totalHours double

Available on Duration, provided by the HumanizedDuration extension

Returns the total duration in floating-point hours.
no setter
totalMinutes double

Available on Duration, provided by the HumanizedDuration extension

Returns the total duration in floating-point minutes.
no setter

Methods

ceilToMinutes() Duration

Available on Duration, provided by the HumanizedDuration extension

Rounds the duration up to the nearest upper minute.
clamp(Duration min, Duration max) Duration

Available on Duration, provided by the HumanizedDuration extension

Clamps this duration to be between min and max.
floorToMinutes() Duration

Available on Duration, provided by the HumanizedDuration extension

Truncates the duration to the nearest lower minute.
isLongerThan(Duration other) bool

Available on Duration, provided by the HumanizedDuration extension

Returns true if this duration is strictly longer than other.
isShorterThan(Duration other) bool

Available on Duration, provided by the HumanizedDuration extension

Returns true if this duration is strictly shorter than other.
isWithin(Duration range, Duration other) bool

Available on Duration, provided by the HumanizedDuration extension

Returns true if this duration is within range difference from other.
progressOf(Duration total, {bool clampResult = true}) double

Available on Duration, provided by the HumanizedDuration extension

Returns a 0.0–1.0 progress value relative to total. Clamps to 0, 1 by default; pass clampResult = false to allow overflow.
remainingIn(Duration total) Duration

Available on Duration, provided by the HumanizedDuration extension

Remaining duration when this is the elapsed time within total.
roundToMinutes() Duration

Available on Duration, provided by the HumanizedDuration extension

Rounds the duration to the nearest minute.
roundToSeconds() Duration

Available on Duration, provided by the HumanizedDuration extension

Rounds the duration to the nearest second.
toFrames(double fps) int

Available on Duration, provided by the HumanizedDuration extension

Frame count at a given fps (e.g. 24, 30, 60).
toHumanizedString() String

Available on Duration, provided by the HumanizedDuration extension

1:02:34 or 2:05 — no forced padding on leading minute
toPaddedString() String

Available on Duration, provided by the HumanizedDuration extension

01:02:34 — always zero-pads all components (useful for fixed-width UI)
toRelativeString() String

Available on Duration, provided by the HumanizedDuration extension

Approximate relative: in 2 hours, 3 minutes ago, just now
toSeconds() double

Available on Duration, provided by the HumanizedDuration extension

Total fractional seconds, including milliseconds.
toVerboseString({bool includeSeconds = true}) String

Available on Duration, provided by the HumanizedDuration extension

1h 2m 34s — verbose, good for settings/accessibility labels
toWordString({bool includeSeconds = true}) String

Available on Duration, provided by the HumanizedDuration extension

1 hour, 2 minutes, 34 seconds — fully written out

Operators

operator *(num factor) Duration

Available on Duration, provided by the HumanizedDuration extension

Multiplies this duration by the given factor.
operator /(num divisor) Duration

Available on Duration, provided by the HumanizedDuration extension

Divides this duration by the given divisor.

Static Methods

fromFrames(int frames, double fps) Duration

Available on Duration, provided by the HumanizedDuration extension

Reconstruct from frame count.