xref: /openbsd-src/usr.bin/calendar/paskha.c (revision f7055df57d065ba4f741cc0da1e46b156de29446)
1*f7055df5Smillert /*	$OpenBSD: paskha.c,v 1.7 2015/03/15 00:41:28 millert Exp $	*/
2b1fc8d4cSmillert 
3b1fc8d4cSmillert /*
4b1fc8d4cSmillert  * Copyright (C) 1993-1996 by Andrey A. Chernov, Moscow, Russia.
5b1fc8d4cSmillert  * All rights reserved.
6b1fc8d4cSmillert  *
7b1fc8d4cSmillert  * Redistribution and use in source and binary forms, with or without
8b1fc8d4cSmillert  * modification, are permitted provided that the following conditions
9b1fc8d4cSmillert  * are met:
10b1fc8d4cSmillert  * 1. Redistributions of source code must retain the above copyright
11b1fc8d4cSmillert  *    notice, this list of conditions and the following disclaimer.
12b1fc8d4cSmillert  * 2. Redistributions in binary form must reproduce the above copyright
13b1fc8d4cSmillert  *    notice, this list of conditions and the following disclaimer in the
14b1fc8d4cSmillert  *    documentation and/or other materials provided with the distribution.
15b1fc8d4cSmillert  *
16b1fc8d4cSmillert  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
17b1fc8d4cSmillert  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18b1fc8d4cSmillert  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19b1fc8d4cSmillert  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20b1fc8d4cSmillert  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21b1fc8d4cSmillert  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22b1fc8d4cSmillert  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23b1fc8d4cSmillert  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24b1fc8d4cSmillert  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25b1fc8d4cSmillert  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26b1fc8d4cSmillert  * SUCH DAMAGE.
27b1fc8d4cSmillert  */
28b1fc8d4cSmillert 
29b1fc8d4cSmillert #include <stdio.h>
30b1fc8d4cSmillert 
315990a66aSderaadt #include "calendar.h"
325990a66aSderaadt 
33b1fc8d4cSmillert /* return year day for Orthodox Easter using Gauss formula */
348a44d90fSpjanzen /* (new style result); subtract 13 for old style */
35b1fc8d4cSmillert 
368a44d90fSpjanzen int
paskha(int R)37638175c6Sderaadt paskha(int R)  /*year*/
38b1fc8d4cSmillert {
39b1fc8d4cSmillert 	int a, b, c, d, e;
40b1fc8d4cSmillert 	static int x = 15;
41b1fc8d4cSmillert 	static int y = 6;
428a44d90fSpjanzen 	int cumdays;
43b1fc8d4cSmillert 
44b1fc8d4cSmillert 	a = R % 19;
45b1fc8d4cSmillert 	b = R % 4;
46b1fc8d4cSmillert 	c = R % 7;
47b1fc8d4cSmillert 	d = (19*a + x) % 30;
48b1fc8d4cSmillert 	e = (2*b + 4*c + 6*d + y) % 7;
498a44d90fSpjanzen 	cumdays = 31 + 28;
508a44d90fSpjanzen 	if (isleap(R))
518a44d90fSpjanzen 		cumdays++;
528a44d90fSpjanzen 	return ((cumdays + 22) + (d + e) + 13);
53b1fc8d4cSmillert }
54