duration
Calendar
Prev:timestamp
Next:Using durations


Vocabulary
calendar

Word description
A duration is a period of time years, months, days, hours, minutes, and seconds. All duration slots can store real numbers. Compare two durations with the <=> word.

See also
timestamp

Definition
USING: math ;

IN: calendar

TUPLE: duration
{ year real initial: 0 } { month real initial: 0 }
{ day real initial: 0 } { hour real initial: 0 }
{ minute real initial: 0 } { second real initial: 0 } ;


Methods
USING: calendar math.order ;

M: duration <=> [ duration>years ] compare ;


USING: calendar math timers.private ;

M: duration >nanoseconds duration>nanoseconds >integer ;


USING: calendar math system threads ;

M: duration sleep
duration>nanoseconds >integer nano-count + sleep-until ;


USING: accessors calendar calendar.private kernel ;

M: duration time+
dup timestamp?
[ swap time+ ] [
[ year>> ] +slots [ month>> ] +slots [ day>> ] +slots
[ hour>> ] +slots [ minute>> ] +slots
[ second>> ] +slots 2drop <duration>
] if ;


USING: accessors calendar calendar.private kernel ;

M: duration time-
over timestamp?
[ before time+ ] [
[ year>> ] -slots [ month>> ] -slots [ day>> ] -slots
[ hour>> ] -slots [ minute>> ] -slots
[ second>> ] -slots 2drop <duration>
] if ;