Annotation of src/usr.bin/calendar/pesach.c, Revision 1.3
1.3 ! deraadt 1: /* $OpenBSD: pesach.c,v 1.2 2004/12/10 20:50:45 mickey Exp $ */
1.1 mickey 2:
3: /*
4: * Copyright (c) 2004 Michael Shalayeff
5: * All rights reserved.
6: *
7: * Permission to use, copy, modify, and distribute this software for any
8: * purpose with or without fee is hereby granted, provided that the above
9: * copyright notice and this permission notice appear in all copies.
10: *
11: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15: * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN
16: * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17: * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18: */
19:
20: #include <stdio.h>
21: #include <tzfile.h>
22:
23: #include "calendar.h"
24:
25: /* Calculate the Julian date of Pesach using the Gauss formula */
26:
27: #define T (33. + 14. / 24.)
28: #define L ((1. + 485. / 1080.) / 24. / 19.)
29: #define K ((29. + (12. + 793. / 1080.) / 24. ) / 19.)
30:
31: int
32: pesach(int R)
33: {
34: int a, b, y, cumdays;
35: double d;
36:
37: y = R + 3760;
38:
39: a = (12 * y + 17) % 19;
40: b = y % 4;
41: d = (T - 10 * K + L + 14) + K * a + b / 4. - L * y;
42: cumdays = d;
43:
44: /* the postponement */
45: switch ((int)(cumdays + 3 * y + 5 * b + 5) % 7) {
46: case 1:
47: if (a > 6 && d - cumdays >= (15. + 204. / 1080.) / 24.)
48: cumdays += 2;
49: break;
50:
51: case 0:
52: if (a <= 11 || d - cumdays < (21. + 589. / 1080.) / 24.)
53: break;
54: /* FALLTHROUGH */
55: case 2:
56: case 4:
57: case 6:
58: cumdays++;
59: break;
60: }
61:
62: if (R > 1582)
63: cumdays += R / 100 - R /400 - 2;
64:
65: return (31 + 28 + cumdays + (isleap(R)? 1 : 0));
66: }