Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84 exptools; site ihlpa.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!ihlpa!rjh
From: rjh@ihlpa.UUCP (Randolph J. Herber)
Newsgroups: net.religion.jewish
Subject: Question about Jewish calendar
Message-ID: <711@ihlpa.UUCP>
Date: Tue, 2-Jul-85 18:23:39 EDT
Article-I.D.: ihlpa.711
Posted: Tue Jul  2 18:23:39 1985
Date-Received: Wed, 3-Jul-85 08:48:56 EDT
Distribution: net
Organization: AT&T Bell Laboratories
Lines: 253

Shalom!
I have enclosed with this item a proposed algorithm for converting
a Julian (on or before Oct 4, 1582) or Georgian (on or after Oct 15, 1582)
calendar date to the coresponding Jewish calendar date. I am asking
whether or not the algorithm does an accurate job.

Randolph J. Herber, ...ihnp4!ihlpa!rjh, 312-979-6553 (U.S.A.)
U.S.Mail address Amdahl Corp, C/O Room IH1C220, AT&T Bell Labs, Naperville, IL,
60566-1005

#include 
#include 
/*
This program writes a date (to stdout) according to the Jewish
Calendar.  If no argument is specified, it calls a "ctime"
function to use today's date.  Otherwise, it may be invoked
with 3 arguments -- month, day, year (4-digit negative for BC(E)).
*/

static char *copyright = {
"(C) 1985 Randolph J. Herber  Usage is unrestricted with retention of notice."
};

#define TRUE     1
#define FALSE    0

static int mlen[] = {
	0,31,28,31,30,31,30,31,31,30,31,30,31
};

static int jmlen[] = {
	0,30,29,30,29,30,30,29,30,29,30,29,30,29
};

static char *mname[] = {
	"",
	"Tishri",
	"Chshvn",
	"Kislev",
	"Tebet",
	"Shebat",
	"Adar",
	"VeAdar",
	"Nisan",
	"Iyar",
	"Sivan",
	"Tammuz",
	"Ab",
	"Elul"
};

static short mdays[] = {
	0,   354,   708,  1092,
	1446,  1801,  2185,  2539,
	2923,  3277,  3632,  4016,
	4370,  4724,  5108,  5463,
	5817,  6201,  6555
};

static short mparts[] = {
	0,  9516, 19032, 16381,
	25897,  9493,  6842, 16358,
	13703, 23223,  6819,  4168,
	13684, 23200, 20549,  4145,
	13661, 11010, 20526
};

static short mtype[] = {
	2,     1,     0,     2,
	1,     0,     3,     0,
	2,     1,     0,     2,
	1,     0,     2,     1,
	0,     3,     0
};

static long table1[4][9] = {
	{0,15611,38880,64800, 83855,116640,145211,168480,181440},
	{0, 3444,38880,55284,107124,116640,133044,168480,181440},
	{0, 3444,36229,55284,107124,116640,123528,168480,181440},
	{0, 3444,36229,55284,107124,116640,133044,168480,181440}
};



static short table2[2][9] = {
	{1,3,2,2,3,1,3,1,0},
	{1,3,2,1,3,1,3,1,0}
};



static short table3[] = {
	1,1,2,4,4,6,6,1,0
};

static char *jkind1[] = {
	"", "defective", "normal", "complete"
};

static char *jkind2[] = {
	"", " leap"
};

main(argc,argv)
int argc;
char **argv;
{

	long secs, time();
	struct tm *tbuf, *localtime();
	void exit();
	int year, yr, mo, da, unit(), jyr, jcycle;
	long jdate, jpart, jday, jarg, jstart;
	short yrm1, n, jyear;
	char style, leap, jtype, jleap;

	if (argc > 1 && argc != 4) {
		(void) printf("Usage:  No arguments for today's date,");
		(void) printf(" or '%s   '.\n", *argv);
		(void) exit(1);
	}
	else if (argc == 1) {
		secs = time((long *)0);
		tbuf = localtime(&secs);
		mo = tbuf->tm_mon + 1;
		da = tbuf->tm_mday;
		year = tbuf->tm_year + 1900;
	}
	else {
		mo = atoi(argv[1]);
		da = atoi(argv[2]);
		year = atoi(argv[3]);
	}

	if (year != 0 && year >= -3761 && year < 10000) {
		yr = year > 0 ? year : year + 1;
		style = year > 1582;
		leap = style
		    ? (((yr % 4) == 0) && ((yr % 100) != 0)) ||
			((yr % 400) == 0)
		    : ((yr % 4) == 0);
		mlen[2] = leap ? 29 : 28;
		if (mo >=1 && mo <= 12 && da >= 1 && da <= mlen[mo] &&
		    !(year == 1582 && (mo == 1 || mo == 2 ||
		    (mo == 10 && da >= 5 && da <= 14)))) {
			if (year == 1582 && mo == 10) {
				mlen[10] = 21;
				if (da >= 15) da -= 10;
			} else {
				mlen[10] = 31;
			}
			yrm1 = yr - 1;
			jdate = 1721423l+yrm1*365+unit(yrm1,4)+da;
			for (n=1;n