On this page:
gen:  time-arithmetic-provider
time-arithmetic-provider?
+  hours
-hours
+  minutes
-minutes
+  seconds
-seconds
+  milliseconds
-milliseconds
+  microseconds
-microseconds
+  nanoseconds
-nanoseconds
+  time-period
-time-period
7.7

12 Time Arithmetic

An interface that defines time arithmetic operations. It is implemented by all objects that satisfy either time-provider? or period?.

procedure

(time-arithmetic-provider? x)  boolean?

  x : any/c
Returns #t if x implements gen:time-arithmetic-provider; #f otherwise.

Adds or subtracts n hours to/from t, returning a fresh time arithmetic provider the same type as t.

Examples:
> (+hours (time 22) 4)

#<time 02:00:00>

> (-hours (datetime 1970) 12)

#<datetime 1969-12-31T12:00:00>

> (+hours (moment 2015 3 8 1 #:tz "America/New_York") 1)

#<moment 2015-03-08T03:00:00-04:00[America/New_York]>

> (-hours (years 5) 20)

#<period of 5 years, -20 hours>

Adds or subtracts n minutes to/from t, returning a fresh time arithmetic provider the same type as t.

Examples:
> (+minutes (time 22) 4)

#<time 22:04:00>

> (-minutes (datetime 1970) 12)

#<datetime 1969-12-31T23:48:00>

> (+minutes (moment 2015 3 8 1 23 59 #:tz "America/New_York") 1)

#<moment 2015-03-08T01:24:59-05:00[America/New_York]>

> (-minutes (years 5) 20)

#<period of 5 years, -20 minutes>

Adds or subtracts n seconds to/from t, returning a fresh time arithmetic provider the same type as t.

Examples:
> (+seconds (time 22) 4)

#<time 22:00:04>

> (-seconds (datetime 1970) 12)

#<datetime 1969-12-31T23:59:48>

> (+seconds (moment 2015 3 8 1 59 59 #:tz "America/New_York") 1)

#<moment 2015-03-08T03:00:00-04:00[America/New_York]>

> (-seconds (years 5) 20)

#<period of 5 years, -20 seconds>

Adds or subtracts n milliseconds to/from t, returning a fresh time arithmetic provider the same type as t.

Examples:
> (+milliseconds (time 22) 4)

#<time 22:00:00.004>

> (-milliseconds (datetime 1970) 12)

#<datetime 1969-12-31T23:59:59.988>

> (+milliseconds (moment 2015 3 8 1 59 59 999000000 #:tz "America/New_York") 1)

#<moment 2015-03-08T03:00:00-04:00[America/New_York]>

> (-milliseconds (years 5) 20)

#<period of 5 years, -20 milliseconds>

Adds or subtracts n microseconds to/from t, returning a fresh time arithmetic provider the same type as t.

Examples:
> (+microseconds (time 22) 4)

#<time 22:00:00.000004>

> (-microseconds (datetime 1970) 12)

#<datetime 1969-12-31T23:59:59.999988>

> (+microseconds (moment 2015 3 8 1 59 59 999999000 #:tz "America/New_York") 1)

#<moment 2015-03-08T03:00:00-04:00[America/New_York]>

> (-microseconds (years 5) 20)

#<period of 5 years, -20 microseconds>

Adds or subtracts n nanoseconds to/from t, returning a fresh time arithmetic provider the same type as t.

Examples:
> (+nanoseconds (time 22) 4)

#<time 22:00:00.000000004>

> (-nanoseconds (datetime 1970) 12)

#<datetime 1969-12-31T23:59:59.999999988>

> (+nanoseconds (moment 2015 3 8 1 59 59 999999999 #:tz "America/New_York") 1)

#<moment 2015-03-08T03:00:00-04:00[America/New_York]>

> (-nanoseconds (years 5) 20)

#<period of 5 years, -20 nanoseconds>

Adds or subtracts p to/from t, returning a fresh time arithmetic provider the same type as t.

Examples:
> (+time-period (time 22) (hours -4))

#<time 18:00:00>

> (+time-period (moment 2015 3 8 1 59 59 999999999 #:tz "America/New_York") (nanoseconds 1))

#<moment 2015-03-08T03:00:00-04:00[America/New_York]>

> (-time-period (years 6) (seconds 5))

#<period of 6 years, -5 seconds>