On this page:
date
date?
jdn->date
date->iso8601
date=?
date<?
date<=?
date>?
date>=?
date-order
8.12

2 Dates🔗ℹ

Gregor provides a date struct that represents a calendar date without a time or time zone. Unfortunately, the name date conflicts with an existing, incompatible definition in racket/base.

The author of this package considered other names, including Date (with a capital D) and local-date (à la Joda-Time) but in the end decided to live with the incompatibility. Gregor’s date, along with its companion data structures (time, datetime, and moment) should be considered a replacement of, not a supplement to, the built-in Racket date.

procedure

(date year [month day])  date?

  year : exact-integer?
  month : (integer-in 1 12) = 1
  day : (day-of-month/c year month) = 1
Constructs a date with the given year, month, and day.

Examples:
> (date 1941 12 7)

#<date 1941-12-07>

> (date 1965 7)

#<date 1965-07-01>

> (date 1970)

#<date 1970-01-01>

procedure

(date? x)  boolean?

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

procedure

(jdn->date jdn)  date?

  jdn : exact-integer?
Returns the date corresponding to the given Julian day number, which is the number of solar days that have elapsed since 12:00 UT on November 24, 4714 BC in the proleptic Gregorian calendar.

Examples:
> (jdn->date 0)

#<date -4713-11-24>

> (jdn->date 2440588)

#<date 1970-01-01>

procedure

(date->iso8601 d)  string?

  d : date?
Returns an ISO 8601 string representation of d.

Examples:
> (date->iso8601 (date 1941 12 7))

"1941-12-07"

> (date->iso8601 (date 1965 7))

"1965-07-01"

> (date->iso8601 (date 1970))

"1970-01-01"

procedure

(date=? x y)  boolean?

  x : date?
  y : date?

procedure

(date<? x y)  boolean?

  x : date?
  y : date?

procedure

(date<=? x y)  boolean?

  x : date?
  y : date?

procedure

(date>? x y)  boolean?

  x : date?
  y : date?

procedure

(date>=? x y)  boolean?

  x : date?
  y : date?
Comparison functions on dates.

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

#t

> (date<? (date 1941 12 7) (date 1965 7))

#t

> (date>? (date 1492) (date 2015))

#f

An order defined on dates.

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

'=

> (date-order (date 1941 12 7) (date 1965 7))

'<

> (date-order (date 2015) (date 1492))

'>

> (make-splay-tree date-order)

#<splay-tree*>