← index

Span

inherits Object

A mixed-unit, calendar-aware duration: years, months, weeks, days, and time units held as SEPARATE fields — "1 month" stays 1 month until it meets a date, where Date/DateTime arithmetic applies it correctly (end-of-month clamping, DST). Contrast Duration, which is a fixed length of time.

Parse ISO 8601 ('P1Y2M3D') or the friendly form ('1y 2mo'); combine with +: / -: field-wise. Equality is FIELDWISE: 1h60m — whether they're the same depends on a calendar, so Span refuses to guess (and has no <: for the same reason).

(Span.parse:'P1Y2M').s                     "* -> 1y 2mo
((Span.years:1) + (Span.months:2)).iso8601 "* -> 'P1Y2M'
extended at core/16-serialize.qn:38

The calendar span, as an ISO 8601 duration ('P1Y2M'; Span.parse: reads it back).

Class methods

days:Integer

A Span of exactly n calendar days (may be negative). A calendar day is not always 24 hours — applying it across a DST change keeps the wall-clock time.

(Span.days:3).iso8601     "* -> 'P3D'

native

hours:Integer

A Span of exactly n hours (may be negative).

native

minutes:Integer

A Span of exactly n minutes (may be negative).

native

months:Integer

A Span of exactly n calendar months (may be negative).

native

parse:String

The Span an ISO 8601 duration ('P1Y2M3DT4H') or friendly form ('1y 2mo') denotes. Not parseable → ValueError.

(Span.parse:'P1Y2M3D').days       "* -> 3
(Span.parse:'1h 30m').minutes     "* -> 30

native

seconds:Integer

A Span of exactly n seconds (may be negative).

native

weeks:Integer

A Span of exactly n weeks (may be negative).

native

years:Integer

A Span of exactly n calendar years (may be negative).

native

zero

The empty Span — every unit zero; the identity for +:.

native

Instance methods

+:Span

The field-wise sum: each unit adds independently — 1y + 2mo is 1y 2mo, and 1h + 60m stays 1h 60m (units never convert; without a calendar there is no correct conversion). Per-unit overflow throws an ArithmeticError.

((Span.years:1) + (Span.months:2)).s     "* -> 1y 2mo

native

-:Span

The field-wise difference — +: with every unit of the argument negated.

native

==:

FIELDWISE equality: every unit must match — 1h is not 60m (whether they name the same length depends on a calendar, so Span refuses to guess). A non-Span argument is simply unequal.

(Span.hours:1) == (Span.minutes:60)     "* -> false
(Span.hours:1) == (Span.hours:1)        "* -> true

native

asData

core/16-serialize.qn:39

asDuration

The equivalent fixed Duration — defined only for a span of pure time units. A span with calendar units (years/months/weeks/days) has no fixed length, so it throws a ValueError rather than guessing.

(Span.parse:'PT1H30M').asDuration.asSeconds     "* -> 5400.0

native

days

The days field alone.

native

hours

The hours field alone.

native

iso8601

The canonical ISO 8601 duration string, for serialization.

((Span.years:1) + (Span.hours:2)).iso8601     "* -> 'P1YT2H'

native

microseconds

The microseconds field alone.

native

milliseconds

The milliseconds field alone.

native

minutes

The minutes field alone.

native

months

The months field alone.

native

nanoseconds

The nanoseconds field alone.

native

negate

The same units with every sign flipped.

(Span.parse:'P1Y2M').negate.iso8601     "* -> '-P1Y2M'

native

s

A human-readable rendering (jiff's friendly form). For a machine-readable form use iso8601.

(Span.parse:'P1Y2M3D').s     "* -> 1y 2mo 3d

native

seconds

The seconds field alone — fractional seconds parse into the millisecond/microsecond/nanosecond fields, not here.

native

weeks

The weeks field alone.

native

years

The years field alone (no conversion from other units).

native