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

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:00Z[UTC]>

> (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

(posix->moment posix [tz])  moment?

  posix : real?
  tz : tz/c = (current-timezone)
Returns the moment corresponding to the given POSIX time, which is the number of seconds that have elapsed since 00:00 UTC on January 1, 1970.

Examples:
> (posix->moment 0)

#<moment 1970-01-01T00:00:00Z[UTC]>

> (posix->moment 1000000000.0 "America/New_York")

#<moment 2001-09-08T21:46:40-04:00[America/New_York]>

> (posix->moment 1638490827 "Etc/UTC")

#<moment 2021-12-03T00:20:27Z[Etc/UTC]>

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-07:52"

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-07:52[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)

#<splay-tree*>