Annotation of src/usr.bin/calendar/ostern.c, Revision 1.6
1.6 ! deraadt 1: /* $OpenBSD: ostern.c,v 1.5 2004/12/10 15:31:01 mickey Exp $ */
1.1 millert 2:
3: /*
4: * Copyright (c) 1996 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
5: * All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: *
16: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26: * SUCH DAMAGE.
27: *
1.6 ! deraadt 28: * $Id: ostern.c,v 1.5 2004/12/10 15:31:01 mickey Exp $
1.1 millert 29: */
30:
31: #ifndef lint
1.6 ! deraadt 32: static const char rcsid[] = "$OpenBSD: ostern.c,v 1.5 2004/12/10 15:31:01 mickey Exp $";
1.1 millert 33: #endif /* not lint */
34:
35: #include <stdio.h>
36: #include <time.h>
1.3 pjanzen 37: #include <tzfile.h>
1.4 deraadt 38:
39: #include "calendar.h"
1.1 millert 40:
41: /* return year day for Easter */
42:
1.6 ! deraadt 43: int
! 44: easter(int year) /* 0 ... abcd, NOT since 1900 */
1.1 millert 45: {
1.6 ! deraadt 46: int e_a, e_b, e_c, e_d, e_e,e_f, e_g, e_h, e_i, e_k;
! 47: int e_l, e_m, e_n, e_p, e_q;
1.1 millert 48:
1.6 ! deraadt 49: /* silly, but it works */
! 50: e_a = year % 19;
! 51: e_b = year / 100;
! 52: e_c = year % 100;
! 53:
! 54: e_d = e_b / 4;
! 55: e_e = e_b % 4;
! 56: e_f = (e_b + 8) / 25;
! 57: e_g = (e_b + 1 - e_f) / 3;
! 58: e_h = ((19 * e_a) + 15 + e_b - (e_d + e_g)) % 30;
! 59: e_i = e_c / 4;
! 60: e_k = e_c % 4;
! 61: e_l = (32 + 2 * e_e + 2 * e_i - (e_h + e_k)) % 7;
! 62: e_m = (e_a + 11 * e_h + 22 * e_l) / 451;
! 63: e_n = (e_h + e_l + 114 - (7 * e_m)) / 31;
! 64: e_p = (e_h + e_l + 114 - (7 * e_m)) % 31;
! 65: e_p = e_p + 1;
! 66:
! 67: e_q = 31 + 28 + e_p;
! 68: if (isleap(year))
! 69: e_q++;
1.1 millert 70:
1.6 ! deraadt 71: if (e_n == 4)
1.1 millert 72: e_q += 31;
73:
74: #if DEBUG
1.6 ! deraadt 75: printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
! 76: e_a, e_b, e_c, e_d, e_e, e_f, e_g, e_h,
! 77: e_i, e_k, e_l, e_m, e_n, e_p, e_q);
1.1 millert 78: #endif
79:
1.6 ! deraadt 80: return (e_q);
1.1 millert 81: }