Path: utzoo!attcan!uunet!mcvax!unido!un21!josef From: josef@un21 Newsgroups: comp.sources.wanted Subject: Re: Wanted: General Date Arithmatic - (nf) Message-ID: <5800012@un21.UUCP> Date: 8 Sep 88 09:59:00 GMT References: <6006@ihlpf.UUCP> Lines: 87 Nf-ID: #R:ihlpf:-600600:un21:5800012:000:2693 Nf-From: un21!josef Sep 8 10:59:00 1988 The solution to Your problem lies in the julian calendar (named after Mr. J. Ceasar, Emperor of Rome, 100-44 BC) In this calendar system, the days are counted starting at some day in ancient history (just like UNIX counts seconds, weren't these people smart?) I enclose two routines jd() and dj() that convert a (so-called gregorian, named after pope Gregory the ???.)) date, as we use it, to a julian day-number and vice-versa. So You can do something like: dj(jd(1988, 9, 8) + 14, &year, &month, &day); to calculate the date of the day in two weeks time. (NOTE: Years are not since 1900 but full years: "19"88!!!!, so beware if You use localtime()!!) I have extracted these routines from two programs I have written around them, so they may contain editing-bugs. The algorithm works fine, I've tried it on the 28th/29th of February in leap years (guess what happend if You calculate the next day) I cannot quite remember where I got them from. All I remember is that it was a book about operations research with programs and subroutines written in FORTRAN. There were also some subroutines to calculate the day of the week (given ???) and the date of easter given a year. If You are interested in them as well, please let me know, I'll dig them out. ---- Cut here ---- /* Convert the number jd, which corresponds to a certain day ** in the julian calendar, into a date in the gregorian calendar */ dj(jd, year, month, day) long dj; int *year, *month, *day; { long l, n; l = jd + 68569; n = 4 * l / 146097; l = l - (146097 * n + 3) / 4; *year = 4000 * (l + 1) / 1461001; l = l -1461* *year / 4 + 31; *month = 80 * l / 2447; *day = l - 2447 * *month / 80; l = *month / 11; *month = *month + 2 - 12 * l; *year = 100 * (n - 49) + l + *year; } /* A (meaningful) date in the gregorian calendar ** is converted to a number that corresponds to a ** day in the julian calendar such that the ** difference between two converted numbers yields ** the number of days between the two dates */ long jd(year, month, day) int year, month, day; { register long j, l; j = (month - 14) / 12; l = year + j + 4800; return day - 32075 + 1461 * l / 4 + 367 * (month - 2 - 12 * j) / 12 - 3 * ((l + 100) / 100) / 4; } ---- Cut here ---- * ** Josef Moellers * * paper-mail: ***** * c/o Nixdorf Computer AG * * Abt. EG-3 * * Unterer Frankfurter Weg * * D-4790 Paderborn * * telephone: * * (+49) 5251 104691 ***** * e-mail: * * (USA) uunet!linus!nixbur!nixpbe!mollers.pad ** (!USA) mcvax!unido!nixpbe!mollers.pad * PS: Please use e-mail address, josef@un21 is of no use Standard disclaimer: Blablabla opinion blablabla employer blablabla!