Developers » Gregorian Date

Gregorian Date is a pure OCaml library for performing calculations based on the Gregorian calendar.

This is a library of useful date calculations using the Gregorian calendar, as used in most Western countries, and increasingly in the East. Although the Gregorian calendar was adopted in 1582, this library extends it back through to 1 AD.

It is inspired and derived from Perl's Date::Calc.

Copyright (C) 2004 Merjis Ltd., Richard W.M. Jones (OCaml version)
Copyright (C) 1995 - 2002 by Steffen Beyer (Perl Date::Calc)

Warning

Gregorian Date is deprecated. Please use Julien Signoles' calendar package instead.

Download software

The library is distributed under the terms of the GNU Library General Public License (LGPL) with the special OCaml linking exception.

gregoriandate-1.0.1.tar.gz (approx. 14K)

Example usage

$ ocaml -I +gregoriandate

       Objective Caml version 3.08.1

# #load "gregorianDate.cma";;
# open GregorianDate;;
# days_in_year 2004;;
- : int = 366
# business_of_standard (2004, 10, 24);;
- : (int * int) * int = ((2004, 43), 7)
# easter_sunday 2005;;
- : int * int * int = (2005, 3, 27)
# day_of_week (2004, 10, 24);;
- : int = 7
# nth_weekday_of_month (2004, 10) 7 4;;
- : int * int * int = (2004, 10, 24)
# add_delta_days (2004, 10, 24) 100;;
- : int * int * int = (2005, 2, 1)

etc.

Patches

Pierre Boulet writes:

I have found a bug in the gregorian date library. When the result of add_delta_days should be December 31st of a leap year, the function returns January 1st of the same year.

example:

# add_delta_days (2004,12,31) 0;;                                               
- : int * int * int = (2004, 1, 1)

Here is a unified patch that solves the problem:

diff -u gregoriandate-1.0.1/gregorianDate.ml gregoriandate/gregorianDate.ml

--- gregoriandate-1.0.1/gregorianDate.ml        2004-10-24 20:45:06.000000000 +0200
+++ gregoriandate/gregorianDate.ml      2005-04-03 12:56:20.000000000 +0200
@@ -76,8 +76,7 @@
   let day = days - year_to_days year in
   let year, day =
     if day < 1 then (
-      let year = year-1 in
-      year, days - year_to_days year
+      year, days - year_to_days (year-1)
     ) else
       year+1, day in
   let leap = index_of_bool (leap_year year) in

Merjis

effective marketing for the web

Merjis specialises in innovative marketing,
accessibility, search engine optimisation (SEO),
and development for the web.