spock@ihlpf.ATT.COM (Weiss) (09/07/88)
I would like to get my hands on (can you get hands on software?) some functions that can to arithmatic on dates. Things like: today + 2 weeks. Anybody have anything like that? -- Ed Weiss "I thought it was generally accepted, sir, that att!ihlpf!spock vulcans are an advanced and most honorable race." "They are, they are. And damn annoying at times."
jherr@umbio.MIAMI.EDU (Jack Herrington) (09/07/88)
in article <6006@ihlpf.ATT.COM>, spock@ihlpf.ATT.COM (Weiss) says: > > I would like to get my hands on (can you get hands on software?) > some functions that can to arithmatic on dates. Things like: > today + 2 weeks. Anybody have anything like that? > Yes, I have a program called 'greg' I got off of simtel20.arpa a while ago that does gregorian conversions julian->mm/dd/yy, mm/dd/yy->julian, etc. Gives you days of the week, so on and so fourth. FTP umbio.miami.edu (129.171.64.204) and look in pub to grab it. -Jack jherr%umbio@umigw.miami.edu
lew@gsg.UUCP (Paul Lew) (09/08/88)
In article <6006@ihlpf.ATT.COM> spock@ihlpf.UUCP (55235-Weiss,E.J.) writes: >I would like to get my hands on (can you get hands on software?) >some functions that can to arithmatic on dates. Things like: >today + 2 weeks. Anybody have anything like that? I once wrote a program called 'dnt' for BSD system so I could insert today's date into vi buffer with the style I like. It accepts a date format sort of like the date for system V. There are options to add/subtract number from the date so you can get date for tomorrow. It only does arithmetic on day, not hour, minute. It is short: 273 lines (no comment) 360 lines (with comment) dnt.c It might not be general enough for you. -- Paul Lew {oliveb,harvard,decvax}!gsg!lew (UUCP) General Systems Group, 5 Manor Parkway, Salem, NH 03079 (603) 893-1000
josef@un21 (09/08/88)
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!
andrew@riddle.UUCP (Andrew Beattie) (09/13/88)
in article <6006@ihlpf.ATT.COM>, spock@ihlpf.ATT.COM (Weiss) says: > > I would like to get my hands on (can you get hands on software?) > some functions that can to arithmatic on dates. Things like: > today + 2 weeks. Anybody have anything like that? > This is my all-time favorite hack! There follows a shell script which will tell you things like what date is next Friday: ------ cut here ------ ############################################################################ # whenis : find out date relative to today : Andrew Beattie 20/5/87 # # mcvax!ukc!reading!riddle!andrew # # andrew@sphinx.co.uk # ############################################################################ # I place this program in the public domain but please keep this header # # on it - I want the fame and glory! # ############################################################################ if [ $# = 0 ] then echo 'whenis today' echo 'whenis [next|last|this] sunday|monday|tuesday|wednesday|th...' exit fi # store current daylight adjustment light=`echo $TZ | cut -c4-` # find day of week and put '-' in front of it now=`date '+-%w'` for i do case $i in today) now=0 ;; next) now="$now +7" ;; last) now="$now -7" ;; tomorrow) now="1" ;; yesterday) now="-1" ;; sunday) now="$now +0" ;; monday) now="$now +1" ;; tuesday) now="$now +2" ;; wednesday) now="$now +3" ;; thursday) now="$now +4" ;; friday) now="$now +5" ;; saturday) now="$now +6" ;; esac done # work out number of hours adjustment adj=`echo "$light + ( -24 * ( $now ) )" |bc` # now for the magic - adjust the time zone by the given number # of hours and let date do the hard work. TZ=GMT$adj date