xref: /freebsd/lib/libcalendar/calendar.3 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
1306a501fSWolfgang Helbig.\" Copyright (c) 1997 Wolfgang Helbig
2306a501fSWolfgang Helbig.\" All rights reserved.
3306a501fSWolfgang Helbig.\"
4306a501fSWolfgang Helbig.\" Redistribution and use in source and binary forms, with or without
5306a501fSWolfgang Helbig.\" modification, are permitted provided that the following conditions
6306a501fSWolfgang Helbig.\" are met:
7306a501fSWolfgang Helbig.\" 1. Redistributions of source code must retain the above copyright
8306a501fSWolfgang Helbig.\"    notice, this list of conditions and the following disclaimer.
9306a501fSWolfgang Helbig.\" 2. Redistributions in binary form must reproduce the above copyright
10306a501fSWolfgang Helbig.\"    notice, this list of conditions and the following disclaimer in the
11306a501fSWolfgang Helbig.\"    documentation and/or other materials provided with the distribution.
12306a501fSWolfgang Helbig.\"
13306a501fSWolfgang Helbig.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14306a501fSWolfgang Helbig.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15306a501fSWolfgang Helbig.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16306a501fSWolfgang Helbig.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17306a501fSWolfgang Helbig.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18306a501fSWolfgang Helbig.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19306a501fSWolfgang Helbig.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20306a501fSWolfgang Helbig.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21306a501fSWolfgang Helbig.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22306a501fSWolfgang Helbig.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23306a501fSWolfgang Helbig.\" SUCH DAMAGE.
24306a501fSWolfgang Helbig.\"
25306a501fSWolfgang Helbig.Dd November 29, 1997
26306a501fSWolfgang Helbig.Dt CALENDAR 3
27306a501fSWolfgang Helbig.Os
28306a501fSWolfgang Helbig.Sh NAME
29306a501fSWolfgang Helbig.Nm easterg ,
304000696cSWolfgang Helbig.Nm easterog ,
314000696cSWolfgang Helbig.Nm easteroj ,
32306a501fSWolfgang Helbig.Nm gdate ,
33306a501fSWolfgang Helbig.Nm jdate ,
34306a501fSWolfgang Helbig.Nm ndaysg ,
35306a501fSWolfgang Helbig.Nm ndaysj ,
36306a501fSWolfgang Helbig.Nm week ,
37306a501fSWolfgang Helbig.Nm weekday
38eb083802SRuslan Ermilov.Nd Calendar arithmetic for the Christian era
39844e8a66SAlexey Zelkin.Sh LIBRARY
40844e8a66SAlexey Zelkin.Lb libcalendar
41306a501fSWolfgang Helbig.Sh SYNOPSIS
4232eef9aeSRuslan Ermilov.In calendar.h
43fa183770SWolfgang Helbig.Ft struct date *
44fa183770SWolfgang Helbig.Fn easterg "int year" "struct date *dt"
45fa183770SWolfgang Helbig.Ft struct date *
46fa183770SWolfgang Helbig.Fn easterog "int year" "struct date *dt"
47fa183770SWolfgang Helbig.Ft struct date *
48fa183770SWolfgang Helbig.Fn easteroj "int year" "struct date *dt"
49fa183770SWolfgang Helbig.Ft struct date *
50fa183770SWolfgang Helbig.Fn gdate "int nd" "struct date *dt"
51fa183770SWolfgang Helbig.Ft struct date *
52fa183770SWolfgang Helbig.Fn jdate "int nd" "struct date *dt"
53306a501fSWolfgang Helbig.Ft int
54fa183770SWolfgang Helbig.Fn ndaysg "struct date *dt"
55306a501fSWolfgang Helbig.Ft int
56fa183770SWolfgang Helbig.Fn ndaysj "struct date *dt"
57306a501fSWolfgang Helbig.Ft int
58306a501fSWolfgang Helbig.Fn week "int nd" "int *year"
59306a501fSWolfgang Helbig.Ft int
60306a501fSWolfgang Helbig.Fn weekday "int nd"
61306a501fSWolfgang Helbig.Sh DESCRIPTION
62306a501fSWolfgang HelbigThese functions provide calendar arithmetic for a large range of years,
631a0a9345SRuslan Ermilovstarting at March 1st, year zero (i.e., 1 B.C.) and ending way beyond
64306a501fSWolfgang Helbigyear 100000.
65fa183770SWolfgang Helbig.Pp
66306a501fSWolfgang HelbigPrograms should be linked with
67306a501fSWolfgang Helbig.Fl lcalendar .
68fa183770SWolfgang Helbig.Pp
69306a501fSWolfgang HelbigThe functions
704000696cSWolfgang Helbig.Fn easterg ,
714000696cSWolfgang Helbig.Fn easterog
72306a501fSWolfgang Helbigand
734000696cSWolfgang Helbig.Fn easteroj
74306a501fSWolfgang Helbigstore the date of Easter Sunday into the structure pointed at by
75306a501fSWolfgang Helbig.Fa dt
76306a501fSWolfgang Helbigand return a pointer to this structure.
77306a501fSWolfgang HelbigThe function
78306a501fSWolfgang Helbig.Fn easterg
79306a501fSWolfgang Helbigassumes Gregorian Calendar (adopted by most western churches after 1582) and
804000696cSWolfgang Helbigthe functions
814000696cSWolfgang Helbig.Fn easterog
824000696cSWolfgang Helbigand
834000696cSWolfgang Helbig.Fn easteroj
844000696cSWolfgang Helbigcompute the date of Easter Sunday according to the orthodox rules
854000696cSWolfgang Helbig(Western churches before 1582, Greek and Russian Orthodox Church
86306a501fSWolfgang Helbiguntil today).
874000696cSWolfgang HelbigThe result returned by
884000696cSWolfgang Helbig.Fn easterog
894000696cSWolfgang Helbigis the date in Gregorian Calendar, whereas
904000696cSWolfgang Helbig.Fn easteroj
914000696cSWolfgang Helbigreturns the date in Julian Calendar.
92fa183770SWolfgang Helbig.Pp
93306a501fSWolfgang HelbigThe functions
94306a501fSWolfgang Helbig.Fn gdate ,
95306a501fSWolfgang Helbig.Fn jdate ,
96306a501fSWolfgang Helbig.Fn ndaysg
97306a501fSWolfgang Helbigand
98306a501fSWolfgang Helbig.Fn ndaysj
99306a501fSWolfgang Helbigprovide conversions between the common "year, month, day" notation
100306a501fSWolfgang Helbigof a date and the "number of days" representation, which is better suited
101c6ff3a1bSSheldon Hearnfor calculations.
102c6ff3a1bSSheldon HearnThe days are numbered from March 1st year 1 B.C., starting
103306a501fSWolfgang Helbigwith zero, so the number of a day gives the number of days since March 1st,
1041a0a9345SRuslan Ermilovyear 1 B.C.
1051a0a9345SRuslan ErmilovThe conversions work for nonnegative day numbers only.
106fa183770SWolfgang Helbig.Pp
107306a501fSWolfgang HelbigThe
108306a501fSWolfgang Helbig.Fn gdate
109306a501fSWolfgang Helbigand
110306a501fSWolfgang Helbig.Fn jdate
111306a501fSWolfgang Helbigfunctions
112306a501fSWolfgang Helbigstore the date corresponding to the day number
113306a501fSWolfgang Helbig.Fa nd
114306a501fSWolfgang Helbiginto the structure pointed at by
115306a501fSWolfgang Helbig.Fa dt
116306a501fSWolfgang Helbigand return a pointer to this structure.
117fa183770SWolfgang Helbig.Pp
118306a501fSWolfgang HelbigThe
119306a501fSWolfgang Helbig.Fn ndaysg
120306a501fSWolfgang Helbigand
121306a501fSWolfgang Helbig.Fn ndaysj
122306a501fSWolfgang Helbigfunctions
123306a501fSWolfgang Helbigreturn the day number of the date pointed at by
124306a501fSWolfgang Helbig.Fa dt .
125fa183770SWolfgang Helbig.Pp
126306a501fSWolfgang HelbigThe
127306a501fSWolfgang Helbig.Fn gdate
128306a501fSWolfgang Helbigand
129306a501fSWolfgang Helbig.Fn ndaysg
130306a501fSWolfgang Helbigfunctions
131fa183770SWolfgang Helbigassume Gregorian Calendar after October 4, 1582 and Julian Calendar before,
132306a501fSWolfgang Helbigwhereas
133306a501fSWolfgang Helbig.Fn jdate
134306a501fSWolfgang Helbigand
135306a501fSWolfgang Helbig.Fn ndaysj
136306a501fSWolfgang Helbigassume Julian Calendar throughout.
137fa183770SWolfgang Helbig.Pp
138c6ff3a1bSSheldon HearnThe two calendars differ by the definition of the leap year.
139c6ff3a1bSSheldon HearnThe
140306a501fSWolfgang HelbigJulian Calendar says every year that is a multiple of four is a
141c6ff3a1bSSheldon Hearnleap year.
142c6ff3a1bSSheldon HearnThe Gregorian Calendar excludes years that are multiples of
143306a501fSWolfgang Helbig100 and not multiples of 400.
144306a501fSWolfgang HelbigThis means the years 1700, 1800, 1900, 2100 are not leap years
145306a501fSWolfgang Helbigand the year 2000 is
146306a501fSWolfgang Helbiga leap year.
147fa183770SWolfgang HelbigThe new rules were inaugurated on October 4, 1582 by deleting ten
148c6ff3a1bSSheldon Hearndays following this date.
149c6ff3a1bSSheldon HearnMost catholic countries adopted the new
150fa183770SWolfgang Helbigcalendar by the end of the 16th century, whereas others stayed with
151c6ff3a1bSSheldon Hearnthe Julian Calendar until the 20th century.
152c6ff3a1bSSheldon HearnThe United Kingdom and
1531a0a9345SRuslan Ermilovtheir colonies switched on September 2, 1752.
1541a0a9345SRuslan ErmilovThey already had to
155fa183770SWolfgang Helbigdelete 11 days.
156fa183770SWolfgang Helbig.Pp
157306a501fSWolfgang HelbigThe function
158306a501fSWolfgang Helbig.Fn week
159306a501fSWolfgang Helbigreturns the number of the week which contains the day numbered
160306a501fSWolfgang Helbig.Fa nd .
161306a501fSWolfgang HelbigThe argument
162306a501fSWolfgang Helbig.Fa *year
163306a501fSWolfgang Helbigis set with the year that contains (the greater part of) the week.
164306a501fSWolfgang HelbigThe weeks are numbered per year starting with week 1, which is the
165306a501fSWolfgang Helbigfirst week in a year that includes more than three days of the year.
166306a501fSWolfgang HelbigWeeks start on Monday.
167306a501fSWolfgang HelbigThis function is defined for Gregorian Calendar only.
168fa183770SWolfgang Helbig.Pp
169306a501fSWolfgang HelbigThe function
170306a501fSWolfgang Helbig.Fn weekday
1711a0a9345SRuslan Ermilovreturns the weekday (Mo = 0 ..\& Su = 6) of the day numbered
172306a501fSWolfgang Helbig.Fa nd .
173fa183770SWolfgang Helbig.Pp
174fa183770SWolfgang HelbigThe structure
175306a501fSWolfgang Helbig.Fa date
176fa183770SWolfgang Helbigis defined in
177fe08efe6SRuslan Ermilov.In calendar.h .
178306a501fSWolfgang HelbigIt contains these fields:
179306a501fSWolfgang Helbig.Bd -literal -offset indent
180306a501fSWolfgang Helbigint y;          /\(** year (0000 - ????) \(**/
181306a501fSWolfgang Helbigint m;          /\(** month (1 - 12) \(**/
182306a501fSWolfgang Helbigint d;          /\(** day of month (1 - 31) \(**/
183306a501fSWolfgang Helbig.Ed
184fa183770SWolfgang Helbig.Pp
185306a501fSWolfgang HelbigThe year zero is written as "1 B.C." by historians and "0" by astronomers
186306a501fSWolfgang Helbigand in this library.
187306a501fSWolfgang Helbig.Sh SEE ALSO
188306a501fSWolfgang Helbig.Xr ncal 1 ,
189306a501fSWolfgang Helbig.Xr strftime 3
190306a501fSWolfgang Helbig.Sh STANDARDS
191306a501fSWolfgang HelbigThe week number conforms to ISO 8601: 1988.
192306a501fSWolfgang Helbig.Sh HISTORY
193306a501fSWolfgang HelbigThe
194306a501fSWolfgang Helbig.Nm calendar
195306a501fSWolfgang Helbiglibrary first appeared in
196306a501fSWolfgang Helbig.Fx 3.0 .
197a5941fc2SPhilippe Charnier.Sh AUTHORS
198306a501fSWolfgang HelbigThis manual page and the library was written by
199*2b7af31cSBaptiste Daroussin.An Wolfgang Helbig Aq Mt helbig@FreeBSD.org .
200306a501fSWolfgang Helbig.Sh BUGS
201306a501fSWolfgang HelbigThe library was coded with great care so there are no bugs left.
202