6 Date and Time Periods
(require gregor/period) | package: gregor-lib |
procedure
(years n) → date-period?
n : exact-integer?
procedure
(months n) → date-period?
n : exact-integer?
procedure
(weeks n) → date-period?
n : exact-integer?
procedure
(days n) → date-period?
n : exact-integer?
procedure
(hours n) → time-period?
n : exact-integer?
procedure
(minutes n) → time-period?
n : exact-integer?
procedure
(seconds n) → time-period?
n : exact-integer?
procedure
(milliseconds n) → time-period?
n : exact-integer?
procedure
(microseconds n) → time-period?
n : exact-integer?
procedure
(nanoseconds n) → time-period?
n : exact-integer?
> (years 3) #<period of 3 years>
> (days -20) #<period of -20 days>
> (seconds 900) #<period of 900 seconds>
value
> empty-period #<period [empty]>
procedure
(date-period? p) → boolean?
p : period?
(equal? p (period->date-period p))
procedure
(time-period? p) → boolean?
p : period?
(equal? p (period->time-period p))
procedure
(period-empty? p) → boolean?
p : period?
(andmap (compose zero? cdr) (period->list p))
procedure
(period-ref p f) → exact-integer?
p : period? f : temporal-unit/c
> (period-ref (years 10) 'years) 10
> (period-ref (years 10) 'hours) 0
procedure
(period-set p f n) → period?
p : period? f : temporal-unit/c n : exact-integer
> (period-set (years 10) 'years -10) #<period of -10 years>
> (period-set (years 10) 'hours -10) #<period of 10 years, -10 hours>
procedure
(period->list p)
→ (listof (cons/c temporal-unit/c exact-integer?)) p : period?
> (period->list (years 10))
'((years . 10)
(months . 0)
(weeks . 0)
(days . 0)
(hours . 0)
(minutes . 0)
(seconds . 0)
(milliseconds . 0)
(microseconds . 0)
(nanoseconds . 0))
> (period->list (period))
'((years . 0)
(months . 0)
(weeks . 0)
(days . 0)
(hours . 0)
(minutes . 0)
(seconds . 0)
(milliseconds . 0)
(microseconds . 0)
(nanoseconds . 0))
> (period->list (period [hours 20] [minutes 10] [seconds 5]))
'((years . 0)
(months . 0)
(weeks . 0)
(days . 0)
(hours . 20)
(minutes . 10)
(seconds . 5)
(milliseconds . 0)
(microseconds . 0)
(nanoseconds . 0))
procedure
p : period?
procedure
p : period?
procedure
(negate-period p) → period?
p : period?
value
date-units : (listof symbol?) = '(years months weeks days)
value
time-units : (listof symbol?)
=
'(hours minutes seconds milliseconds microseconds nanoseconds)
value
temporal-units : (listof symbol?)
=
'(years months weeks days hours minutes seconds milliseconds microseconds nanoseconds)
value
date-unit/c : flat-contract?
value
time-unit/c : flat-contract?
value
temporal-unit/c : flat-contract?
procedure
(date-period-between p1 p2 [fields]) → date-period?
p1 : date-provider? p2 : date-provider? fields : (listof date-unit/c) = date-units
> (date-period-between (date 1959 5 22) (date 1980 1 18) '(years months days)) #<period of 20 years, 7 months, 27 days>
procedure
(time-period-between p1 p2 [fields]) → time-period?
p1 : time-provider? p2 : time-provider? fields : (listof time-unit/c) = time-units
> (time-period-between (datetime 1970) (now)) #<period of 404003 hours, 18 minutes, 11 seconds, 687 milliseconds, 750 microseconds>
procedure
(period-between p1 p2 [fields]) → period?
p1 : datetime-provider? p2 : datetime-provider? fields : (listof temporal-unit/c) = temporal-units
> (period-between (datetime 1970) (now) '(years months days hours minutes seconds)) #<period of 46 years, 1 month, 1 day, 11 hours, 18 minutes, 11 seconds>