[BACK]Return to pesach.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / calendar

File: [local] / src / usr.bin / calendar / pesach.c (download)

Revision 1.4, Sun Mar 15 00:41:28 2015 UTC (9 years, 1 month ago) by millert
Branch: MAIN
CVS Tags: OPENBSD_7_5_BASE, OPENBSD_7_5, OPENBSD_7_4_BASE, OPENBSD_7_4, OPENBSD_7_3_BASE, OPENBSD_7_3, OPENBSD_7_2_BASE, OPENBSD_7_2, OPENBSD_7_1_BASE, OPENBSD_7_1, OPENBSD_7_0_BASE, OPENBSD_7_0, OPENBSD_6_9_BASE, OPENBSD_6_9, OPENBSD_6_8_BASE, OPENBSD_6_8, OPENBSD_6_7_BASE, OPENBSD_6_7, OPENBSD_6_6_BASE, OPENBSD_6_6, OPENBSD_6_5_BASE, OPENBSD_6_5, OPENBSD_6_4_BASE, OPENBSD_6_4, OPENBSD_6_3_BASE, OPENBSD_6_3, OPENBSD_6_2_BASE, OPENBSD_6_2, OPENBSD_6_1_BASE, OPENBSD_6_1, OPENBSD_6_0_BASE, OPENBSD_6_0, OPENBSD_5_9_BASE, OPENBSD_5_9, OPENBSD_5_8_BASE, OPENBSD_5_8, HEAD
Changes since 1.3: +1 -2 lines

tzfile.h is an internal header that should never have been installed.
What's worse, the tzfile.h that gets installed is over 20 years old
and doesn't match the real tzfile.h in libc/time.  This makes the
tree safe for /usr/include/tzfile.h removal.  The TM_YEAR_BASE
define has been moved to time.h temporarily until its usage is
replaced by 1900 in the tree.  Actual removal of tzfile.h is pending
a ports build.  Based on a diff from deraadt@

/*	$OpenBSD: pesach.c,v 1.4 2015/03/15 00:41:28 millert Exp $	*/

/*
 * Copyright (c) 2004 Michael Shalayeff
 * All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN
 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <stdio.h>

#include "calendar.h"

/* Calculate the Julian date of Pesach using the Gauss formula */

#define	T	(33. + 14. / 24.)
#define	L	((1.  + 485. / 1080.) / 24. / 19.)
#define	K	((29. + (12. + 793. / 1080.) / 24. ) / 19.)

int
pesach(int R)
{
	int a, b, y, cumdays;
	double d;

	y = R + 3760;

	a = (12 * y + 17) % 19;
	b = y % 4;
	d = (T - 10 * K + L + 14) + K * a +  b / 4. - L * y;
	cumdays = d;

	/* the postponement */
	switch ((int)(cumdays + 3 * y + 5 * b + 5) % 7) {
	case 1:
		if (a > 6 && d - cumdays >= (15. + 204. / 1080.) / 24.)
			cumdays += 2;
		break;

	case 0:
		if (a <= 11 || d - cumdays < (21. + 589. / 1080.) / 24.)
			break;
		/* FALLTHROUGH */
	case 2:
	case 4:
	case 6:
		cumdays++;
		break;
	}

	if (R > 1582)
		cumdays += R / 100 - R /400 - 2;

	return (31 + 28 + cumdays + (isleap(R)? 1 : 0));
}