xref: /freebsd/lib/libcalendar/calendar.3 (revision 8d20be1e22095c27faf8fe8b2f0d089739cc742e)
1.\" Copyright (c) 1997 Wolfgang Helbig
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.\" $FreeBSD$
26.\"
27.Dd November 29, 1997
28.Dt CALENDAR 3
29.Os
30.Sh NAME
31.Nm easterg ,
32.Nm easterog ,
33.Nm easteroj ,
34.Nm gdate ,
35.Nm jdate ,
36.Nm ndaysg ,
37.Nm ndaysj ,
38.Nm week ,
39.Nm weekday
40.Nd Calendar arithmetic for the Christian era
41.Sh LIBRARY
42.Lb libcalendar
43.Sh SYNOPSIS
44.In calendar.h
45.Ft struct date *
46.Fn easterg "int year" "struct date *dt"
47.Ft struct date *
48.Fn easterog "int year" "struct date *dt"
49.Ft struct date *
50.Fn easteroj "int year" "struct date *dt"
51.Ft struct date *
52.Fn gdate "int nd" "struct date *dt"
53.Ft struct date *
54.Fn jdate "int nd" "struct date *dt"
55.Ft int
56.Fn ndaysg "struct date *dt"
57.Ft int
58.Fn ndaysj "struct date *dt"
59.Ft int
60.Fn week "int nd" "int *year"
61.Ft int
62.Fn weekday "int nd"
63.Sh DESCRIPTION
64These functions provide calendar arithmetic for a large range of years,
65starting at March 1st, year zero (i.e., 1 B.C.) and ending way beyond
66year 100000.
67.Pp
68Programs should be linked with
69.Fl lcalendar .
70.Pp
71The functions
72.Fn easterg ,
73.Fn easterog
74and
75.Fn easteroj
76store the date of Easter Sunday into the structure pointed at by
77.Fa dt
78and return a pointer to this structure.
79The function
80.Fn easterg
81assumes Gregorian Calendar (adopted by most western churches after 1582) and
82the functions
83.Fn easterog
84and
85.Fn easteroj
86compute the date of Easter Sunday according to the orthodox rules
87(Western churches before 1582, Greek and Russian Orthodox Church
88until today).
89The result returned by
90.Fn easterog
91is the date in Gregorian Calendar, whereas
92.Fn easteroj
93returns the date in Julian Calendar.
94.Pp
95The functions
96.Fn gdate ,
97.Fn jdate ,
98.Fn ndaysg
99and
100.Fn ndaysj
101provide conversions between the common "year, month, day" notation
102of a date and the "number of days" representation, which is better suited
103for calculations.
104The days are numbered from March 1st year 1 B.C., starting
105with zero, so the number of a day gives the number of days since March 1st,
106year 1 B.C.
107The conversions work for nonnegative day numbers only.
108.Pp
109The
110.Fn gdate
111and
112.Fn jdate
113functions
114store the date corresponding to the day number
115.Fa nd
116into the structure pointed at by
117.Fa dt
118and return a pointer to this structure.
119.Pp
120The
121.Fn ndaysg
122and
123.Fn ndaysj
124functions
125return the day number of the date pointed at by
126.Fa dt .
127.Pp
128The
129.Fn gdate
130and
131.Fn ndaysg
132functions
133assume Gregorian Calendar after October 4, 1582 and Julian Calendar before,
134whereas
135.Fn jdate
136and
137.Fn ndaysj
138assume Julian Calendar throughout.
139.Pp
140The two calendars differ by the definition of the leap year.
141The
142Julian Calendar says every year that is a multiple of four is a
143leap year.
144The Gregorian Calendar excludes years that are multiples of
145100 and not multiples of 400.
146This means the years 1700, 1800, 1900, 2100 are not leap years
147and the year 2000 is
148a leap year.
149The new rules were inaugurated on October 4, 1582 by deleting ten
150days following this date.
151Most catholic countries adopted the new
152calendar by the end of the 16th century, whereas others stayed with
153the Julian Calendar until the 20th century.
154The United Kingdom and
155their colonies switched on September 2, 1752.
156They already had to
157delete 11 days.
158.Pp
159The function
160.Fn week
161returns the number of the week which contains the day numbered
162.Fa nd .
163The argument
164.Fa *year
165is set with the year that contains (the greater part of) the week.
166The weeks are numbered per year starting with week 1, which is the
167first week in a year that includes more than three days of the year.
168Weeks start on Monday.
169This function is defined for Gregorian Calendar only.
170.Pp
171The function
172.Fn weekday
173returns the weekday (Mo = 0 ..\& Su = 6) of the day numbered
174.Fa nd .
175.Pp
176The structure
177.Fa date
178is defined in
179.In calendar.h .
180It contains these fields:
181.Bd -literal -offset indent
182int y;          /\(** year (0000 - ????) \(**/
183int m;          /\(** month (1 - 12) \(**/
184int d;          /\(** day of month (1 - 31) \(**/
185.Ed
186.Pp
187The year zero is written as "1 B.C." by historians and "0" by astronomers
188and in this library.
189.Sh SEE ALSO
190.Xr ncal 1 ,
191.Xr strftime 3
192.Sh STANDARDS
193The week number conforms to ISO 8601: 1988.
194.Sh HISTORY
195The
196.Nm calendar
197library first appeared in
198.Fx 3.0 .
199.Sh AUTHORS
200This manual page and the library was written by
201.An Wolfgang Helbig Aq helbig@FreeBSD.org .
202.Sh BUGS
203The library was coded with great care so there are no bugs left.
204