Outdated egg!

This is an egg for CHICKEN 3, the unsupported old release. You're almost certainly looking for the CHICKEN 4 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

date-info

Introduction

This egg provides a simple interface for calculating lots of useful information about a date. This information can be used for display purposes (eg, displaying a date in various formats), or for complex date arithmetic (eg, finding the third Thursday in July).

Quite simply, it provides a date record type which contains details of the date according to four different calendar systems:

Date records may be created from Julian day numbers, or year/month/day-of-month dates. Support for the other two input calendars will hopefully be implemented one day.

Examples

  (use date-info)
  (define my-date (make-date-from-ymd 1979 4 4)) ; 4th April 1979
  (printf "Julian day number: ~S\n" (date-jdn my-date))
  (printf "ISO date: ~S-~S-~S\n" (date-year my-date) (date-month my-date) (date-day-of-month my-date))
  (printf "ISO ordinal date: ~S-~S\n" (date-year my-date) (date-day-of-year my-date))
  (printf "ISO week date: ~SW~S-~S\n" (date-week-year my-date) (date-week-of-year my-date) (date-day-of-week my-date))
  (printf "The month has ~S days, and the year has ~S days\n" (date-days-in-month my-date) (date-days-in-year my-date))
  (if (date-leap-year? my-date)
    (printf "~S is a leap year\n" (date-year my-date))
    (printf "~S is not a leap year\n" (date-year my-date)))  

Authors

Alaric Blagrave Snell-Pym of Kitten Technologies

License

Copyright (c) 2003-2007, Warhead.org.uk Ltd

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Neither the names of Warhead.org.uk Ltd, Snell Systems, nor Kitten Technologies, nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE

Requirements

None

Interface

(make-date-from-ymd YEAR MONTH DAY)
Creates a date info record for the given date, represented as a year, month number, and day number.
(make-date-from-ymd-int YYYYMMDD)
Creates a date info record for the given date, represented as a year times ten thousand, a month numbers times one hundred, plus a day. Eg, 19790404.
(make-date-from-jdn JDN)
Creates a date info record for the given date, represented as a julian day number.
(date? DATE)
Returns #t if and only if the argument is a date info record.
(date-jdn DATE)
Returns the julian day number
(date-year DATE)
Returns the normal calendar year
(date-month DATE)
Returns the numeric month (1 = January, etc)
(date-day-of-month DATE)
Returns the day of the month
(date-days-in-month DATE)
Returns the length of the month (including getting the right number of days in February for leap years)
(date-day-of-year DATE)
Returns the day of the year (January the 1st is day 1, and it counts up from there)
(date-days-in-year DATE)
Returns the number of days in the year (365, or 366 in a leap year)
(date-leap-year? DATE)
Returns #t if and only if the year is a leap year
(date-yyyymmdd DATE)
Returns the date as a single integer, composed of the year times ten thousand plus the month number times one hundred plus the day.
(date-week-year DATE)
Returns the ISO weekdate year
(date-week-of-year DATE)
Returns the ISO weekdate week
(date-day-of-week DATE)
Returns the ISO weekdate day (Monday is 1, Sunday is 7)

Dependencies

The egg is based around an existing C library I wrote some time ago, which I have included in the scheme source code as embedded C with little modification, so nothing needs to be installed first.

TODO

Version history