On this page:
moment
moment?
moment->iso8601
moment->iso8601/  tzid
moment=?
moment<?
moment<=?
moment>?
moment>=?
moment-order
6.3.90.900

5 Moments

The moment struct represents the combination of a datetime and a time zone.

procedure

(moment year    
  [month    
  day    
  hour    
  minute    
  second    
  nanosecond    
  #:tz tz    
  #:resolve-offset resolve])  moment?
  year : exact-integer?
  month : (integer-in 1 12) = 1
  day : (day-of-month/c year month) = 1
  hour : (integer-in 0 23) = 0
  minute : (integer-in 0 59) = 0
  second : (integer-in 0 59) = 0
  nanosecond : (integer-in 0 999999999) = 0
  tz : tz/c = (current-timezone)
  resolve : offset-resolver/c = resolve-offset/raise
Constructs a moment with the given date and time fields, time zone, and offset-resolver.

Examples:
> (moment 1970)

#<moment 1970-01-01T00:00:00-07:00[America/Denver]>

> (moment 1969 7 21 2 56 #:tz "Etc/UTC")

#<moment 1969-07-21T02:56:00Z[Etc/UTC]>

> (moment 2015 3 8 2 #:tz -18000)

#<moment 2015-03-08T02:00:00-05:00>

> (moment 2015 3 8 2 #:tz "America/New_York")

Illegal moment: local time 2015-03-08T02:00:00 does not

exist in time zone America/New_York

> (moment 2015 3 8 2 #:tz "America/New_York" #:resolve-offset resolve-offset/pre)

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

> (moment 2015 3 8 2 #:tz "America/New_York" #:resolve-offset resolve-offset/post)

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

procedure

(moment? x)  boolean?

  x : any/c
Returns #t if x is a moment; #f otherwise.

procedure

(moment->iso8601 m)  string?

  m : moment?
Returns an ISO 8601 string representation of m. Since ISO 8601 doesn’t support IANA time zones, that data is discarded; only the UTC offset is used in the result. See moment->iso8601/tzid for a function that preserves the IANA time zone information.

Examples:
> (moment->iso8601 (moment 1970 #:tz "Etc/UTC"))

"1970-01-01T00:00:00Z"

> (moment->iso8601 (moment 1969 7 21 2 56 #:tz 0))

"1969-07-21T02:56:00Z"

> (moment->iso8601 (moment 1 2 3 4 5 6 7 #:tz "America/Los_Angeles"))

"0001-02-03T04:05:06.000000007-08:00"

procedure

(moment->iso8601/tzid m)  string?

  m : moment?
Returns a string representation of m comprising the ISO 8610 representation plus the IANA time zone, if m has one.

Examples:
> (moment->iso8601/tzid (moment 1970 #:tz "Etc/UTC"))

"1970-01-01T00:00:00Z[Etc/UTC]"

> (moment->iso8601/tzid (moment 1969 7 21 2 56 #:tz 0))

"1969-07-21T02:56:00Z"

> (moment->iso8601/tzid (moment 1 2 3 4 5 6 7 #:tz "America/Los_Angeles"))

"0001-02-03T04:05:06.000000007-08:00[America/Los_Angeles]"

procedure

(moment=? x y)  boolean?

  x : moment?
  y : moment?

procedure

(moment<? x y)  boolean?

  x : moment?
  y : moment?

procedure

(moment<=? x y)  boolean?

  x : moment?
  y : moment?

procedure

(moment>? x y)  boolean?

  x : moment?
  y : moment?

procedure

(moment>=? x y)  boolean?

  x : moment?
  y : moment?
Comparison functions on moments. These are temporal comparison functions, which take into consideration time zone data. In particular, moment=? does not implement the same notion of equality as equal? on moments.

Examples:
> (moment=? (moment 1970 1 1) (moment 1970))

#t

> (moment=? (moment 1969 12 31 19 #:tz "America/New_York") (moment 1970 #:tz "Etc/UTC"))

#t

> (equal? (moment 1969 12 31 19 #:tz "America/New_York") (moment 1970 #:tz "Etc/UTC"))

#f

> (moment<? (moment 1970 #:tz "Etc/UTC") (moment 1970 #:tz "America/New_York"))

#t

> (moment>? (moment 1970) (moment 1969 7 21 2 56))

#t

An order defined on moments.

Examples:
> (moment-order (moment 1970 1 1) (moment 1970))

'=

> (moment-order (moment 1970) (moment 1969 7 21 2 56))

'>

> (moment-order (moment 1969 7 21 2 56) (moment 1970))

'<

> (make-splay-tree moment-order)

#<compact-splay-tree*>