Previous: Date and time, Up: Physical Quantities

5.6 Time arithmetic and time intervals

The difference of two timepoints may be used to compute a time interval, and an interval added to a timepoint to create another timepoint. Intervals are ordinary physical dimension quantities with dimension of time, and may be format for input or output in several ways. The reader macro #d and the function read-time will read in an interval in ISO8601 format; it should begin with “P” as required by that standard.

All components are of fixed size; for example, a month is 30 days, and a year is 12 months. This may produce some odd-looking results because a year will have only 360 days.

     ANTIK-USER> (+ #d2011-08-01T12:00 #DP1m3d)
     2011-09-03 12:00:00.000
     ANTIK-USER> (- #d2011-09-03T12:00:00.000 #d2011-08-01T12:00)
     ANTIK-USER> (- #d2011-09-03T12:00:00.000 #d2010-09-03T12:00:00.000)

Formatting for an interval is specified by setting the nf parameter :time to :tud for an ISO8601 time unit designator, :alternative for the ISO8601 alternate, or nil for the physical dimension time. Default is :tud.

     ANTIK-USER> (set-nf-options :time :tud)
     ANTIK-USER> #_12345_seconds
     ANTIK-USER> (set-nf-options :time nil)
     ANTIK-USER> #dP8m3dT5h