Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!hao!ames!ptsfa!ihnp4!ihlpa!rjh From: rjh@ihlpa.ATT.COM (45261-Herber) Newsgroups: comp.misc Subject: Re: Julian Date/Day Number Message-ID: <6205@ihlpa.ATT.COM> Date: Tue, 10-Nov-87 10:31:19 EST Article-I.D.: ihlpa.6205 Posted: Tue Nov 10 10:31:19 1987 Date-Received: Fri, 13-Nov-87 05:35:34 EST References: <557@astroatc.UUCP> Reply-To: rjh@ihlpa.UUCP (45261-Herber,R.J.) Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 113 Keywords: Ceasar, Astronomy, Dates, Etc. Astronomical Julian Dates/Day Number number from January 1, 4713 BC. That date was picked because a number of various different calendar cycles come to their initial points then and for most purposes is sufficiently far into the past that all {:-)} useful dates are positive numbers. I am including a program that computes the astronomical Julian Date using the Roman Catholic church's definition of when the switch between the Julian and the Georgian calendars occurred, i.e. Oct 4, 1582 Old Style was followed by Oct 15, 1582 New Style. Randolph J. Herber, Amdahl Sr Sys Eng, ..!ihnp4!ihlpa!rjh, (312) 979-6553, IH 6X213, AT&T Bell Labs, Naperville, IL 60566 #include #include /* This program writes a astronomical Julian date (to stdout). 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). */ #define TRUE 1 #define FALSE 0 static int mlen[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 }; int unit(f1,f2) int f1, f2; { int rmdr; rmdr = f1 % f2; if (rmdr < 0) rmdr += f2; return (f1 - rmdr) / f2; } main(argc,argv) int argc; char **argv; { long secs, time(); struct tm *tbuf, *localtime(); void exit(); int year, yr, mo, da, unit(); long jdate; short yrm1, n; char style,leap; if (argc > 1 && argc != 4) { (void) printf("Usage: No arguments for today's date,"); (void) printf(" or '%s '.\n", argv[0]); (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 > -10000 && 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