KScript docs
EN

duration fields and methods

A field is a plain fact about the value, read with a dot and no brackets: $value.name. A method takes arguments or does work, and is called with ->: $value->name(arguments), or with the value piped in: $value |> name(arguments).

Fields

FieldTypeDescription
.daysnumberThe length in days: 1.5 for 1d12h.
.hoursnumberThe length in hours: 1.5 for 1h30m.
.minutesnumberThe length in minutes: 90 for 1h30m.
.msnumberThe length in milliseconds.
.secondsnumberThe length in seconds: 5400 for 1h30m.

From KScript.Core

#duration->add(other: duration) → duration

The two lengths added: 1h30m->add(45m) is 2h15m.
ParameterTakes
other requiredduration
Example
<let name="x" type="duration" value="'1h30m'" />
<echo>{ $x->add(45m) }</echo>
$x: duration = '1h30m'
echo $x->add(45m)

#duration->after(time?: date) → date

The time this long after a date, or after now.
ParameterTakes
time optionaldate
Example
<let name="x" type="duration" value="'1h30m'" />
<echo>{ $x->after('2026-11-21T09:00:00'->to_date()) }</echo>
$x: duration = '1h30m'
echo $x->after('2026-11-21T09:00:00'->to_date())

#duration->before(time?: date) → date

The time this long before a date, or before now.
ParameterTakes
time optionaldate
Example
<let name="x" type="duration" value="'1h30m'" />
<echo>{ $x->before('2026-11-21T09:00:00'->to_date()) }</echo>
$x: duration = '1h30m'
echo $x->before('2026-11-21T09:00:00'->to_date())

#duration->iso() → string

The length in ISO 8601: PT1H30M.
Example
<let name="x" type="duration" value="'1h30m'" />
<echo>{ $x->iso() }</echo>
$x: duration = '1h30m'
echo $x->iso()

#duration->subtract(other: duration) → duration

The second length taken from this one: 1h30m->subtract(45m) is 45m.
ParameterTakes
other requiredduration
Example
<let name="x" type="duration" value="'1h30m'" />
<echo>{ $x->subtract(45m) }</echo>
$x: duration = '1h30m'
echo $x->subtract(45m)

Methods from any

Methods from string