xref: /freebsd/lib/libcalendar/calendar.3 (revision 783d3ff6d7fae619db8a7990b8a6387de0c677b5)
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.Dd November 29, 1997
26.Dt CALENDAR 3
27.Os
28.Sh NAME
29.Nm easterg ,
30.Nm easterog ,
31.Nm easteroj ,
32.Nm gdate ,
33.Nm jdate ,
34.Nm ndaysg ,
35.Nm ndaysj ,
36.Nm week ,
37.Nm weekday
38.Nd Calendar arithmetic for the Christian era
39.Sh LIBRARY
40.Lb libcalendar
41.Sh SYNOPSIS
42.In calendar.h
43.Ft struct date *
44.Fn easterg "int year" "struct date *dt"
45.Ft struct date *
46.Fn easterog "int year" "struct date *dt"
47.Ft struct date *
48.Fn easteroj "int year" "struct date *dt"
49.Ft struct date *
50.Fn gdate "int nd" "struct date *dt"
51.Ft struct date *
52.Fn jdate "int nd" "struct date *dt"
53.Ft int
54.Fn ndaysg "struct date *dt"
55.Ft int
56.Fn ndaysj "struct date *dt"
57.Ft int
58.Fn week "int nd" "int *year"
59.Ft int
60.Fn weekday "int nd"
61.Sh DESCRIPTION
62These functions provide calendar arithmetic for a large range of years,
63starting at March 1st, year zero (i.e., 1 B.C.) and ending way beyond
64year 100000.
65.Pp
66Programs should be linked with
67.Fl lcalendar .
68.Pp
69The functions
70.Fn easterg ,
71.Fn easterog
72and
73.Fn easteroj
74store the date of Easter Sunday into the structure pointed at by
75.Fa dt
76and return a pointer to this structure.
77The function
78.Fn easterg
79assumes Gregorian Calendar (adopted by most western churches after 1582) and
80the functions
81.Fn easterog
82and
83.Fn easteroj
84compute the date of Easter Sunday according to the orthodox rules
85(Western churches before 1582, Greek and Russian Orthodox Church
86until today).
87The result returned by
88.Fn easterog
89is the date in Gregorian Calendar, whereas
90.Fn easteroj
91returns the date in Julian Calendar.
92.Pp
93The functions
94.Fn gdate ,
95.Fn jdate ,
96.Fn ndaysg
97and
98.Fn ndaysj
99provide conversions between the common "year, month, day" notation
100of a date and the "number of days" representation, which is better suited
101for calculations.
102The days are numbered from March 1st year 1 B.C., starting
103with zero, so the number of a day gives the number of days since March 1st,
104year 1 B.C.
105The conversions work for nonnegative day numbers only.
106.Pp
107The
108.Fn gdate
109and
110.Fn jdate
111functions
112store the date corresponding to the day number
113.Fa nd
114into the structure pointed at by
115.Fa dt
116and return a pointer to this structure.
117.Pp
118The
119.Fn ndaysg
120and
121.Fn ndaysj
122functions
123return the day number of the date pointed at by
124.Fa dt .
125.Pp
126The
127.Fn gdate
128and
129.Fn ndaysg
130functions
131assume Gregorian Calendar after October 4, 1582 and Julian Calendar before,
132whereas
133.Fn jdate
134and
135.Fn ndaysj
136assume Julian Calendar throughout.
137.Pp
138The two calendars differ by the definition of the leap year.
139The
140Julian Calendar says every year that is a multiple of four is a
141leap year.
142The Gregorian Calendar excludes years that are multiples of
143100 and not multiples of 400.
144This means the years 1700, 1800, 1900, 2100 are not leap years
145and the year 2000 is
146a leap year.
147The new rules were inaugurated on October 4, 1582 by deleting ten
148days following this date.
149Most catholic countries adopted the new
150calendar by the end of the 16th century, whereas others stayed with
151the Julian Calendar until the 20th century.
152The United Kingdom and
153their colonies switched on September 2, 1752.
154They already had to
155delete 11 days.
156.Pp
157The function
158.Fn week
159returns the number of the week which contains the day numbered
160.Fa nd .
161The argument
162.Fa *year
163is set with the year that contains (the greater part of) the week.
164The weeks are numbered per year starting with week 1, which is the
165first week in a year that includes more than three days of the year.
166Weeks start on Monday.
167This function is defined for Gregorian Calendar only.
168.Pp
169The function
170.Fn weekday
171returns the weekday (Mo = 0 ..\& Su = 6) of the day numbered
172.Fa nd .
173.Pp
174The structure
175.Fa date
176is defined in
177.In calendar.h .
178It contains these fields:
179.Bd -literal -offset indent
180int y;          /\(** year (0000 - ????) \(**/
181int m;          /\(** month (1 - 12) \(**/
182int d;          /\(** day of month (1 - 31) \(**/
183.Ed
184.Pp
185The year zero is written as "1 B.C." by historians and "0" by astronomers
186and in this library.
187.Sh SEE ALSO
188.Xr ncal 1 ,
189.Xr strftime 3
190.Sh STANDARDS
191The week number conforms to ISO 8601: 1988.
192.Sh HISTORY
193The
194.Nm calendar
195library first appeared in
196.Fx 3.0 .
197.Sh AUTHORS
198This manual page and the library was written by
199.An Wolfgang Helbig Aq Mt helbig@FreeBSD.org .
200.Sh BUGS
201The library was coded with great care so there are no bugs left.
202