From 4000696ce70869ac63f33c1c1cdc47349ad54669 Mon Sep 17 00:00:00 2001 From: Wolfgang Helbig Date: Sun, 7 Dec 1997 19:04:14 +0000 Subject: [PATCH] Added easterog() and easteroj() which compute orthodox easter for Gregorian and Julian Calendar. Suggested by: Andrey --- lib/libcalendar/Makefile | 4 ++-- lib/libcalendar/calendar.3 | 27 ++++++++++++++++------ lib/libcalendar/calendar.h | 5 +++-- lib/libcalendar/easter.c | 46 +++++++++++++++++++++++++------------- 4 files changed, 56 insertions(+), 26 deletions(-) diff --git a/lib/libcalendar/Makefile b/lib/libcalendar/Makefile index fe41148927a8..5e2a34548fdc 100644 --- a/lib/libcalendar/Makefile +++ b/lib/libcalendar/Makefile @@ -1,4 +1,4 @@ -# $Id$ +# $Id: Makefile,v 1.1.1.1 1997/12/04 10:41:49 helbig Exp $ LIB= calendar @@ -6,7 +6,7 @@ SRCS= calendar.c easter.c MAN3= calendar.3 -MLINKS= calendar.3 easterg.3 calendar.3 easterj.3 \ +MLINKS= calendar.3 easterg.3 calendar.3 easterog.3 calendar.3 easteroj.3 \ calendar.3 gdate.3 calendar.3 jdate.3 \ calendar.3 ndaysg.3 calendar.3 ndaysj.3 \ calendar.3 week.3 calendar.3 weekday.3 diff --git a/lib/libcalendar/calendar.3 b/lib/libcalendar/calendar.3 index 4f51a0266f07..0ac65444b074 100644 --- a/lib/libcalendar/calendar.3 +++ b/lib/libcalendar/calendar.3 @@ -22,14 +22,15 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $Id$ +.\" $Id: calendar.3,v 1.1.1.1 1997/12/04 10:41:49 helbig Exp $ .\" .Dd November 29, 1997 .Dt CALENDAR 3 .Os .Sh NAME .Nm easterg , -.Nm easterj , +.Nm easterog , +.Nm easteroj , .Nm gdate , .Nm jdate , .Nm ndaysg , @@ -42,7 +43,9 @@ .Ft date * .Fn easterg "int year" "date *dt" .Ft date * -.Fn easterj "int year" "date *dt" +.Fn easterog "int year" "date *dt" +.Ft date * +.Fn easteroj "int year" "date *dt" .Ft date * .Fn gdate "int nd" "date *dt" .Ft date * @@ -64,18 +67,28 @@ Programs should be linked with .Fl lcalendar . The functions -.Fn easterg +.Fn easterg , +.Fn easterog and -.Fn easterj +.Fn easteroj store the date of Easter Sunday into the structure pointed at by .Fa dt and return a pointer to this structure. The function .Fn easterg assumes Gregorian Calendar (adopted by most western churches after 1582) and -.Fn easterj -assumes Julian Calendar (Western churches before 1582 and Greek Church +the functions +.Fn easterog +and +.Fn easteroj +compute the date of Easter Sunday according to the orthodox rules +(Western churches before 1582, Greek and Russian Orthodox Church until today). +The result returned by +.Fn easterog +is the date in Gregorian Calendar, whereas +.Fn easteroj +returns the date in Julian Calendar. The functions .Fn gdate , diff --git a/lib/libcalendar/calendar.h b/lib/libcalendar/calendar.h index 6c8d8f9da115..8be8d4997c41 100644 --- a/lib/libcalendar/calendar.h +++ b/lib/libcalendar/calendar.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: calendar.h,v 1.1.1.1 1997/12/04 10:41:49 helbig Exp $ */ typedef struct date { int y; /* year */ @@ -32,7 +32,8 @@ typedef struct date { } date; date *easterg(int _year, date *_dt); -date *easterj(int _year, date *_dt); +date *easterog(int _year, date *_dt); +date *easteroj(int _year, date *_dt); date *gdate(int _nd, date *_dt); date *jdate(int _nd, date *_dt); int ndaysg(date *_dt); diff --git a/lib/libcalendar/easter.c b/lib/libcalendar/easter.c index 53021f765d23..fa43837c7a5b 100644 --- a/lib/libcalendar/easter.c +++ b/lib/libcalendar/easter.c @@ -23,11 +23,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: easter.c,v 1.1.1.1 1997/12/04 10:41:49 helbig Exp $ */ #include "calendar.h" +static int easterodn(int y); + /* Compute Easter Sunday in Gregorian Calendar */ date * easterg(int y, date *dt) @@ -47,11 +49,26 @@ easterg(int y, date *dt) return (dt); } -/* Compute Easter Sunday in Julian Calendar */ -date * -easterj(int y, date * dt) +/* Compute the Gregorian date of Easter Sunday in Julian Calendar */ +date * +easterog(int y, date *dt) { + return (gdate(easterodn(y), dt)); +} + +/* Compute the Julian date of Easter Sunday in Julian Calendar */ +date * +easteroj(int y, date * dt) +{ + + return (jdate(easterodn(y), dt)); +} + +/* Compute the day number of Easter Sunday in Julian Calendar */ +static int +easterodn(int y) +{ /* * Table for the easter limits in one metonic (19-year) cycle. 21 * to 31 is in March, 1 through 18 in April. Easter is the first @@ -62,21 +79,20 @@ easterj(int y, date * dt) /* Offset from a weekday to next sunday */ int ns[] = {6, 5, 4, 3, 2, 1, 7}; + date dt; int dn; - /* Assign the easter limit of y to *dt */ - dt->d = mc[y % 19]; + /* Assign the easter limit of y to dt */ + dt.d = mc[y % 19]; - if (dt->d < 21) - dt->m = 4; + if (dt.d < 21) + dt.m = 4; else - dt->m = 3; + dt.m = 3; - dt->y = y; + dt.y = y; - /* Compute the next sunday after the easter limit */ - dn = ndaysj(dt); - dn += ns[weekday(dn)]; - - return (jdate(dn, dt)); + /* Return the next sunday after the easter limit */ + dn = ndaysj(&dt); + return (dn + ns[weekday(dn)]); }