On this page:
gen:  date-provider
date-provider?
->date
->jdn
->year
->quarter
->month
->day
->wday
->yday
->iso-week
->iso-wyear
->iso-wday
sunday?
monday?
tuesday?
wednesday?
thursday?
friday?
saturday?
at-time
at-midnight
at-noon
6.3.90.900

7 Generic Date Operations

value

gen:date-provider : any/c

An interface, implemented by date, datetime, and moment, that supplies generic operations on dates.

procedure

(date-provider? x)  boolean?

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

procedure

(->date d)  date?

  d : date-provider?
Returns the local date corresponding to d.

Examples:
> (->date (date 2000 1 1))

#<date 2000-01-01>

> (->date (datetime 1969 7 21 2 56))

#<date 1969-07-21>

> (->date (moment 2015 3 8 1 #:tz "America/New_York"))

#<date 2015-03-08>

procedure

(->jdn d)  exact-integer?

  d : date-provider?
Returns the Julian day number corresponding to the local date component of d.

Examples:
> (->jdn (date 1970))

2440588

> (->jdn (datetime 1969 7 21 2 56))

2440424

> (->jdn (moment 2015 3 8 1 #:tz "America/New_York"))

2457090

procedure

(->year d)  exact-integer?

  d : date-provider?
Returns the year (in the proleptic Gregorian calendar) of the local date component of d. Years are numbered according to ISO 8601. That is, the year 1 BCE is represented here as the year 0, 2 BCE is -1, and so forth.

Examples:
> (->year (date 1970))

1970

> (->year (datetime -3 3 3 3 33 33))

-3

> (->year (moment 2015 3 8 1 #:tz "America/New_York"))

2015

procedure

(->quarter d)  exact-integer?

  d : date-provider?
Returns the quarter (numbered 1-4) of the local date component of d.

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

1

> (->quarter (datetime 1970 4 1))

2

> (->quarter (moment 1970 7 1 #:tz "America/New_York"))

3

> (->quarter (moment 1970 10 1 #:tz "Etc/UTC"))

4

procedure

(->month d)  exact-integer?

  d : date-provider?
Returns the month (numbered 1-12) of the local date component of d.

Examples:
> (->month (date 1970))

1

> (->month (datetime -3 3 3 3 33 33))

3

> (->month (moment 2015 3 8 1 #:tz "America/New_York"))

3

procedure

(->day d)  exact-integer?

  d : date-provider?
Returns the day of the month of the local date component of d.

Examples:
> (->day (date 1970))

1

> (->day (datetime 1980 2 29))

29

> (->day (moment 2015 3 8 1 #:tz "America/New_York"))

8

procedure

(->wday d)  exact-integer?

  d : date-provider?
Returns the day of the week (numbered 0-6, starting with Sunday) of the local date component of d.

Examples:
> (->wday (date 1970))

4

> (->wday (datetime 1980 2 29))

5

> (->wday (moment 2015 3 8 1 #:tz "America/New_York"))

0

procedure

(->yday d)  exact-integer?

  d : date-provider?
Returns the day of the year (numbered from 1) of the local date component of d.

Examples:
> (->yday (date 1970))

1

> (->yday (datetime 1980 12 31))

366

> (->yday (moment 2015 12 31 #:tz "America/New_York"))

365

procedure

(->iso-week d)  exact-integer?

  d : date-provider?
Returns the ISO 8601 week number of the local date component of d.

Examples:
> (->iso-week (date 2005 1 1))

53

> (->iso-week (datetime 2007 1 1))

1

> (->iso-week (moment 2008 12 31 #:tz "America/New_York"))

1

procedure

(->iso-wyear d)  exact-integer?

  d : date-provider?
Returns the ISO 8601 week-numbering year of the local date component of d.

Examples:
> (->iso-wyear (date 2005 1 1))

2004

> (->iso-wyear (datetime 2007 1 1))

2007

> (->iso-wyear (moment 2008 12 31 #:tz "America/New_York"))

2009

procedure

(->iso-wday d)  exact-integer?

  d : date-provider?
Returns the day of the week, numbered according to ISO 8601 (i.e., 1-7, starting with Monday) of the local date component of d.

Examples:
> (->iso-wday (date 1970))

4

> (->iso-wday (datetime 1980 2 29))

5

> (->iso-wday (moment 2015 3 8 1 #:tz "America/New_York"))

7

procedure

(sunday? d)  boolean?

  d : date-provider?

procedure

(monday? d)  boolean?

  d : date-provider?

procedure

(tuesday? d)  boolean?

  d : date-provider?

procedure

(wednesday? d)  boolean?

  d : date-provider?

procedure

(thursday? d)  boolean?

  d : date-provider?

procedure

(friday? d)  boolean?

  d : date-provider?

procedure

(saturday? d)  boolean?

  d : date-provider?
Predicates that are satisfied when d falls on the named day of the week.

procedure

(at-time d t [#:resolve-offset resolve])  datetime-provider?

  d : date-provider?
  t : time-provider?
  resolve : offset-resolver/c = resolve-offset/raise
Returns an object combining the date components of d with the time components of t. The result should not lose any information from d (other than whatever time components d may have, which will be replaced by those of t). So, for example, if d is a moment, the result will also be a moment with the same time zone as d.

Examples:
> (at-time (date 1970) (time 14 30))

#<datetime 1970-01-01T14:30:00>

> (at-time (datetime 2015 3 8 2) (time 2))

#<datetime 2015-03-08T02:00:00>

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

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

procedure

(at-midnight d [#:resolve-offset resolve])  datetime-provider?

  d : date-provider?
  resolve : offset-resolver/c = resolve-offset/raise
Equivalent to (at-time d (time 0) #:resolve-offset resolve).

procedure

(at-noon d [#:resolve-offset resolve])  datetime-provider?

  d : date-provider?
  resolve : offset-resolver/c = resolve-offset/raise
Equivalent to (at-time d (time 12) #:resolve-offset resolve).