Date-Routines for C/UNIX ? HELP
mccaugh at s.cs.uiuc.edu
mccaugh at s.cs.uiuc.edu
Tue Sep 12 16:02:00 AEST 1989
I'm sorry if my code (in the first comment) is less than neat: I did
test it out extensively so it at least works, but could be more efficient.
In particular, the line assigning to variable lp_yrs should read:
lp_yrs = (yyyy-1)/4 - 492;
I tried modifying that line but it was already networked.
Not sure what was meant by requesting 'previous day' or 'next day': were
these requests for a new date or for the name of said day? In any event,
just take the code I gave for day-of-week and add/subtract 86400 (= #(secs)
per day) to value 'secs' to get a new duration in seconds, then proceed
from there.
The easiest part is checking date-validity, as the call to 'localtime()'
returns info to check against the given date. Upon its return, we can
first query if UNIX returns a date consistent with our own:
/* check: dd == tp->tm_mday */
/* check: mm == tp->tm_mon */
/* check: yyyy == tp->tm_year */
and only then should the day-of-week be printed out.
Again, hope this helps.
Scott McCaughrin
More information about the Comp.lang.c
mailing list