11 Date Arithmetic
procedure
x : any/c
procedure
(+years d n [#:resolve-offset resolve]) → date-arithmetic-provider?
d : date-arithmetic-provider? n : exact-integer? resolve : offset-resolver/c = resolve-offset/retain
procedure
(-years d n [#:resolve-offset resolve]) → date-arithmetic-provider?
d : date-arithmetic-provider? n : exact-integer? resolve : offset-resolver/c = resolve-offset/retain
> (+years (date 1970) 5) #<date 1975-01-01>
> (-years (date 1970) 1) #<date 1969-01-01>
> (-years (datetime 1980 2 29) 1) #<datetime 1979-02-28T00:00:00>
> (+years (moment 2014 3 8 2 #:tz "America/New_York") 1) #<moment 2015-03-08T03:00:00-04:00[America/New_York]>
> (+years (moment 2014 3 8 2 #:tz "America/New_York") 1 #:resolve-offset resolve-offset/pre) #<moment 2015-03-08T01:59:59.999999999-05:00[America/New_York]>
> (-years (days 2) 5) #<period of -5 years, 2 days>
procedure
(+months d n [#:resolve-offset resolve])
→ date-arithmetic-provider? d : date-arithmetic-provider? n : exact-integer? resolve : offset-resolver/c = resolve-offset/retain
procedure
(-months d n [#:resolve-offset resolve])
→ date-arithmetic-provider? d : date-arithmetic-provider? n : exact-integer? resolve : offset-resolver/c = resolve-offset/retain
> (+months (date 1970) 30) #<date 1972-07-01>
> (+months (datetime 2015 12 29) 2) #<datetime 2016-02-29T00:00:00>
> (-months (datetime 2015 3 29) 1) #<datetime 2015-02-28T00:00:00>
> (+months (moment 2015 2 8 2) 1) #<moment 2015-03-08T03:00:00-06:00[America/Denver]>
> (+months (moment 2015 2 8 2) 1 #:resolve-offset resolve-offset/raise) Illegal moment: local time 2015-03-08T02:00:00 does not
exist in time zone America/Denver
> (-months (months 8) 3) #<period of 5 months>
procedure
(+weeks d n [#:resolve-offset resolve]) → date-arithmetic-provider?
d : date-arithmetic-provider? n : exact-integer? resolve : offset-resolver/c = resolve-offset/retain
procedure
(-weeks d n [#:resolve-offset resolve]) → date-arithmetic-provider?
d : date-arithmetic-provider? n : exact-integer? resolve : offset-resolver/c = resolve-offset/retain
> (+weeks (date 1970) 3) #<date 1970-01-22>
> (-weeks (date 1970) 3) #<date 1969-12-11>
> (+weeks (datetime 2016 2 22) 1) #<datetime 2016-02-29T00:00:00>
> (-weeks (moment 2015 3 29 2) 3 #:resolve-offset resolve-offset/raise) Illegal moment: local time 2015-03-08T02:00:00 does not
exist in time zone America/Denver
> (+weeks (minutes 7) 1) #<period of 1 week, 7 minutes>
procedure
(+days d n [#:resolve-offset resolve]) → date-arithmetic-provider?
d : date-arithmetic-provider? n : exact-integer? resolve : offset-resolver/c = resolve-offset/retain
procedure
(-days d n [#:resolve-offset resolve]) → date-arithmetic-provider?
d : date-arithmetic-provider? n : exact-integer? resolve : offset-resolver/c = resolve-offset/retain
> (+days (date 1970) 3) #<date 1970-01-04>
> (-days (date 1970) 3) #<date 1969-12-29>
> (+days (datetime 2016 2 28) 1) #<datetime 2016-02-29T00:00:00>
> (-days (moment 2015 3 11 2) 3 #:resolve-offset resolve-offset/raise) Illegal moment: local time 2015-03-08T02:00:00 does not
exist in time zone America/Denver
> (-days (period [years 5] [hours 2]) 20) #<period of 5 years, -20 days, 2 hours>
procedure
(+date-period d p [#:resolve-offset resolve])
→ date-arithmetic-provider? d : date-arithmetic-provider? p : date-period? resolve : offset-resolver/c = resolve-offset/retain
procedure
(-date-period d p [#:resolve-offset resolve])
→ date-arithmetic-provider? d : date-arithmetic-provider? p : date-period? resolve : offset-resolver/c = resolve-offset/retain
> (+date-period (date 1970) (years 10)) #<date 1980-01-01>
> (-date-period (date 1970) (weeks 1)) #<date 1969-12-25>
> (+date-period (minutes 4) (days 2)) #<period of 2 days, 4 minutes>