Duration

← Reference
Io

Thin IoObject wrapper around the plain-C Duration struct (years, days, hours, minutes, seconds). All arithmetic and formatting live in Duration.c; this file only bridges Io message sends to the C API, manages lifecycle (tag / clone / free / compare), and registers the proto. Durations interoperate with IoDate for +/- arithmetic — see IoDate_add / IoDate_subtract, which read the C Duration via IoDuration_duration — and with IoNumber through asNumber / fromNumber, treating seconds as the canonical scalar form.

IoDuration_asSeconds(self)

Inverse of IoDuration_fromSeconds_: collapses the multi-field Duration into a single double. Used by the Io-visible asNumber method and by any C caller that needs a scalar.

IoDuration_compare(self, other)

Tag compareFunc. Delegates to Duration_compare when both sides are Durations; otherwise falls back to IoObject_defaultCompare so that cross-type comparisons still produce a stable ordering rather than an error.

IoDuration_duration(self)

Accessor exposed to other C code (IoDate in particular) so it can reach the underlying Duration struct without duplicating the DATA macro. Returns a borrowed pointer; the caller must not free it.

IoDuration_free(self)

Tag freeFunc. Releases the heap-allocated C Duration struct; the IoObject header itself is freed by the collector.

IoDuration_fromSeconds_(self, s)

In-place mutator that rewrites every Duration field from a single seconds value. Thin wrapper around Duration_fromSeconds_; the split exists so IoDuration_newWithSeconds_ and the Io-level fromNumber method share one path.

IoDuration_new(state)

Clones the registered proto. Preferred C-level constructor when a blank Duration is needed before any field is set.

IoDuration_newTag(state)

Builds the Duration tag and wires in clone / free / compare function pointers. No mark func is needed since Duration's C payload holds no IoObject references — it is a pure numeric struct.

IoDuration_newWithSeconds_(state, s)

Factory for a Duration initialized from a double seconds value. Used by IoDate_subtract when a Date-minus-Date difference is returned as a Duration, and anywhere else the VM needs to surface an elapsed time to Io code.

IoDuration_proto(state)

Creates the Duration proto with its full method table (field accessors for years/days/hours/minutes/seconds, asString/asNumber conversion, and +=/-= operators). Allocates a zeroed C Duration struct and registers the proto under "Duration" on the VM state so IoDuration_new can clone it later.

IoDuration_rawClone(proto)

Tag cloneFunc. Allocates a fresh C Duration struct on the clone (never shared with the proto) and copies its fields via Duration_copy_, so each IoDuration owns its own numeric state.

IoMessage_locals_durationArgAt_(self, locals, n)

Argument coercion helper used from other files (notably IoDate.c) to fetch the n-th argument as an IoDuration. Raises a type error via IoMessage_locals_numberArgAt_errorForType_ when the value is not a Duration, mirroring the pattern used by numberArgAt_ and seqArgAt_ elsewhere in the VM.