This site is a static rendering of the Trac instance that was used by R7RS-WG1 for its work on R7RS-small (PDF), which was ratified in 2013. For more information, see Home. For a version of this page that may be more recent, see TimePeriodsCowan in WG2's repo for R7RS-large.

Time­Periods­Cowan

cowan
2010-11-29 12:48:18
3history
source

Time durations and intervals

A duration is an immutable object belonging to a distinct type and representing a period of time according a particular chronology. In the ISO, Gregorian, and Julian chronologies, it is the sum of some number of years, months, weeks, days, hours, minutes, and seconds.

A time interval is an immutable object belonging to a distinct type and representing the elapsed time between two instants of time. See TimeCowan for the definition of instants; see TimeAdvancedCowan for the definition of date objects.

Duration procedures

(make-duration chronology alist)

Constructs and returns a duration based on chronology. Alist is an alist mapping duration field names understood by that chronology to their values. In the ISO, Gregorian, and Julian calendars, the field names are years, months, weeks, days, hours, minutes, and seconds. The values of each field must be exact integers, except that the smallest unit present may be any rational number.

(duration? obj)

Returns #t if obj is a duration, and #f otherwise.

(duration->alist duration)

Constructs and returns an alist mapping field names existing in duration into their values. Fields mapped to #f don't appear in the alist.

(duration-field fieldname duration)

Returns the value associated with fieldname. For example, (duration-field 'weeks d) returns the number of weeks in duration d. If the duration was not constructed with a particular unit, #f is returned instead. No conversion is done: a 7-day interval is not considered equivalent to a 1-week interval, for example.

Time interval procedures

An interval represents the time between two or more instants. Intervals belong to an immutable disjoint type.

(make-interval date-or-duration-1 date-or-duration-2)

Constructs and returns an interval which:

An error is signaled if both arguments are durations, or if the arguments do not share the same chronology, or the dates do not have enough fields to specify an instant.

(interval? obj)

Returns #t if obj is an interval and #f otherwise.

(interval-start interval)

(interval-stop interval)

(interval-duration interval)

Returns the start date, stop date, and duration of interval. Depending on how the interval was constructed, at least one of these will have to be calculated.

(make-repeating-interval interval [ repetition ])

Constructs and returns a interval from interval that repeats repetition times, where repetition is an exact positive integer. An error is signaled if interval is already a repeated interval. If repetition is omitted, the new interval is repeated indefinitely often.

(interval-repetition interval)

Returns the repetition count of interval. If interval is not a repeated interval, returns 1.