Next Previous Up Top Contents Index

7 The Date Module

7.3 Representing durations

Date/time intervals, called durations, are modeled in a style quite similar to that of SQL. There are two, effectively disjoint, classes of duration: one with a resolution of months (for example, 3 years, 2 months) and the other with a resolution of microseconds (for example, 50 days, 6 hours, 23 minutes). The first is <year/month-duration> and the second <day/time-duration>.

An important distinction between <day/time-duration> and <year/month-duration> is that a given instance of <day/time-duration> is always a fixed unit of a fixed length, whereas a <year/month-duration> follows the vagaries of the calendar. So if you have a <date> that represents, for example, the 5th of some month, adding a <year/month-duration> of 1 month to that will always take you to the 5th of the following month, whether that is an interval of 28, 29, 30, or 31 days.

<duration>

Sealed abstract instantiable class

This class is the used to represent durations. It is a subclass of <number>, and it has two subclasses, described below.
<year/month-duration>

Sealed class

Represents durations in units of calendar months. It is a subclass of <duration>.
<day/time-duration>

Sealed class

Represents durations in units of microseconds. It is a subclass of <duration>.

The following functions and methods are available for creating durations, and decoding them into their constituent integer parts.

encode-year/month-duration

Function

encode-year/month-duration years months => duration

Creates an instance of <year/month-duration>.
encode-day/time-duration

Function

encode-day/time-duration days hours minutes seconds microseconds 
=> duration 

Creates an instance of <day/time-duration>.
decode-duration

Sealed generic function

decode-duration duration => #rest components

Decodes an instance of <duration> into its constituent parts. There are methods for this generic function that specialize on <year/month-duration> and <day/time-duration> respectively, as described below.
decode-duration

Sealed method

decode-duration duration => years months 

Decodes an instance of <year/month-duration> into its constituent parts.
decode-duration

Sealed method

decode-duration duration => days hours minutes seconds microseconds 

Decodes an instance of <day/time-duration> into its constituent parts.

System and I/O Reference - 31 MAR 2000

Next Previous Up Top Contents Index