envzn
0.8 · beta · not released

Library / Date and time / Date and time / TimeDuration

CLASSIMPLEMENTS Cloneable, Hashable, Equatable<TimeDuration>, Comparable<TimeDuration>

TimeDuration

Signed wall-clock duration with millisecond precision.

Fields 5

int64 days
int64 hours
int64 minutes
int64 seconds
int64 millis

Constructors 3

INIT()

Zero duration.

INIT(int32 days, int32 hours, int32 minutes, int32 seconds, int32 millis)

Explicit-component constructor. Each parameter contributes linearly to totalMs (1 day = 86_400_000 ms; 1 hour = 3_600_000 ms; 1 minute = 60_000 ms; 1 second = 1_000 ms; 1 ms = 1 ms). The broken-down fields below are then derived from totalMs, so (1 day, 25 hours, 0, 0, 0) yields .days = 2, .hours = 1.

INIT(int64 totalMs)

Direct totalMs constructor. Used by arithmetic-operator results (DateTime->operator-(DateTime), TimeDuration±TimeDuration) where the int64 difference is already known and re-running the component composition would just round-trip.

Methods 9

METHOD getTotalMs() RETURNS int64
reads

Signed milliseconds — the canonical underlying value.

METHOD __op_plus__(REFERENCE TimeDuration other) RETURNS TimeDuration
reads

td1 + td2 lowering. Returns a new TimeDuration whose totalMs is the int64 sum; no overflow check (int64 ms range is ~±292M years, well past anything practical).

METHOD __op_minus__(REFERENCE TimeDuration other) RETURNS TimeDuration
reads

td1 - td2 lowering.

METHOD negate() RETURNS TimeDuration
reads

Named unary negation. Unary - on classes is out of V1 scope (Phase 0 #6 LOCKED); callers compose td->negate() instead.

METHOD isLessThan(REFERENCE TimeDuration other) RETURNS boolean
reads

Strict less-than on totalMs. Drives derived </<=/>/>=.

METHOD equals(REFERENCE TimeDuration other) RETURNS boolean
reads

Two TimeDurations are equal iff their totalMs match.

METHOD hash() RETURNS uint64
reads

FNV-1a 64-bit hash of totalMs, mixed as 8 little-endian bytes. Mirrors the per-byte mixing String.hash() uses; equal totalMs → equal hash, the Equatable contract.

METHOD clone() RETURNS TimeDuration
reads

Field copy. Routes through INIT(int64) so the decomposition runs once on the clone; totalMs is the source of truth, the public fields are derived.

METHOD format() RETURNS String
reads

ISO-8601 duration text — [-]P[nD]T[nH][nM][nS[.mmm]], millisecond precision: PT0S for zero, a leading - for a negative duration, and fractional seconds (PT1.500S) only when there are sub-second millis. TOTAL — every duration has a text form. The inverse is DurationText.parse (DurationText.ev); serde carries a TimeDuration field through this pair (I.P.i).