9 Generic Datetime Operations
value
gen:datetime-provider : any/c
In fact, gen:datetime-provider is also implemented by date, which can be treated like a datetime with its time component set to midnight. This should be considered an experimental part of the design, which may be removed.
procedure
(datetime-provider? x) → boolean?
x : any/c
procedure
(->datetime/local t) → datetime?
t : datetime-provider?
> (->datetime/local (datetime 1969 7 21 2 56)) #<datetime 1969-07-21T02:56:00>
> (->datetime/local (moment 2015 3 8 1 #:tz "America/New_York")) #<datetime 2015-03-08T01:00:00>
procedure
(->datetime/utc t) → datetime?
t : datetime-provider?
For a datetime, ->datetime/local and ->datetime/utc return the same thing.
> (->datetime/utc (datetime 1969 7 21 2 56)) #<datetime 1969-07-21T02:56:00>
> (->datetime/utc (moment 2015 3 8 1 #:tz "America/New_York")) #<datetime 2015-03-08T06:00:00>
procedure
t : datetime-provider?
procedure
t : datetime-provider?
procedure
(years-between t1 t2) → exact-integer?
t1 : datetime-provider? t2 : datetime-provider?
procedure
(months-between t1 t2) → exact-integer?
t1 : datetime-provider? t2 : datetime-provider?
procedure
(weeks-between t1 t2) → exact-integer?
t1 : datetime-provider? t2 : datetime-provider?
procedure
(days-between t1 t2) → exact-integer?
t1 : datetime-provider? t2 : datetime-provider?
procedure
(hours-between t1 t2) → exact-integer?
t1 : datetime-provider? t2 : datetime-provider?
procedure
(minutes-between t1 t2) → exact-integer?
t1 : datetime-provider? t2 : datetime-provider?
procedure
(seconds-between t1 t2) → exact-integer?
t1 : datetime-provider? t2 : datetime-provider?
procedure
(milliseconds-between t1 t2) → exact-integer?
t1 : datetime-provider? t2 : datetime-provider?
procedure
(microseconds-between t1 t2) → exact-integer?
t1 : datetime-provider? t2 : datetime-provider?
procedure
(nanoseconds-between t1 t2) → exact-integer?
t1 : datetime-provider? t2 : datetime-provider?
> (years-between (datetime 2000) (datetime 2001)) 1
> (years-between (datetime 2001) (datetime 2002)) 1
> (months-between (datetime 2000 3) (datetime 1999 12)) -3
> (days-between (moment 2015 3 8 1 59 #:tz "America/Los_Angeles") (moment 2015 3 16 1 59 #:tz "America/Los_Angeles")) 8
> (weeks-between (moment 2015 3 8 1 59 #:tz "America/Los_Angeles") (moment 2015 3 16 1 59 #:tz "Etc/UTC")) 1
> (days-between (datetime 2015) (datetime 2015 1 14 23 59 59)) 13
> (hours-between (moment 2000 #:tz "Etc/UTC") (moment 1999 12 31 19 #:tz "America/New_York")) 0
> (minutes-between (datetime 2000) (datetime 2000 1 2)) 1440
> (seconds-between (datetime 2000) (datetime 2000 1 2)) 86400
> (milliseconds-between (datetime 2000) (datetime 2000 1 2)) 86400000
> (microseconds-between (datetime 2000) (datetime 2000 1 2)) 86400000000
> (nanoseconds-between (datetime 2000) (datetime 2000 1 2)) 86400000000000
procedure
(with-timezone t tz #:resolve-offset resolve-offset) → timezone-provider? t : datetime-provider? tz : tz/c resolve-offset : offset-resolver/c
This function is a blunt instrument and is rarely needed. If your aim is to translate a moment into another that represents the same point in absolute time but in a different time zone, then you’re looking for adjust-timezone.
> (with-timezone (datetime 2000) "America/New_York") #<moment 2000-01-01T00:00:00-05:00[America/New_York]>
> (with-timezone (moment 2000 #:tz "America/New_York") "Europe/Paris") #<moment 2000-01-01T00:00:00+01:00[Europe/Paris]>