home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name stsdate -- Return the system date in USA format
- *
- * Synopsis ercode = stsdate(pdate,pyear,pmonth,pday);
- *
- * int ercode Error code is -1 if current system date
- * is not a legal date, 0 if o.k.
- * char *pdate Pointer to string in which the date is
- * returned.
- * int *pyear,*pmonth,*pday Pointers to variables in which
- * the year, month and day are returned.
- *
- * Description This function returns the system date as integers and as
- * a string containing the month and day of the week. For
- * example, 8/17/83 is returned as
- *
- * Wednesday August 17, 1983
- *
- * The day of week algorithm is valid only for the 20th and
- * 21st centuries; any date outside this range returns a
- * nonzero error code and the null string.
- *
- * The date string, pdate, must be large enough to
- * accommodate the largest date string since sprintf() is
- * used. If it is not, memory will be overwritten. pdate
- * should be large enough to store a string of length 30.
- *
- * Returns int ercode Returned error code
- * char *pdate Date string
- * int *pyear,*pmonth,*pday The date as numeric values.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1983, 1984, 1985, 1986
- *
- **/
-
- #include <stdio.h>
-
- #include <bstring.h>
-
- int stsdate(pdate,pyear,pmonth,pday)
- char *pdate;
- register int *pyear,*pmonth;
- int *pday;
- {
-
- /* The static array day_offset measures the offset into the week */
- /* for each month of the 20th century. Notice that day_offset[0] */
- /* is not a legal month. */
-
- static int day_offset[] = {0,6,2,2,5,0,3,5,1,4,6,2,4};
- static char *day_name[] =
- {
- "Sunday","Monday","Tuesday",
- "Wednesday","Thursday",
- "Friday","Saturday"
- };
- static char *month_name[] =
- {
- "", /* Illegal Month */
- "January","February","March",
- "April","May","June",
- "July","August","September",
- "October","November","December"
- };
- register int leap_yrs; /* Number of leap years */
- register int day_index;
-
- qyretdat(pyear,pmonth,pday); /* Get system date */
-
- if ( utrange(*pyear,1900,2099)
- || utrange(*pmonth,1,12)
- || utrange(*pday,1,31))
- {
- *pdate = '\0';
- return(-1); /* Date is out of range */
- }
-
- /* Now count the leap years and compute the number of days (mod 7)*/
- /* to get the day of the week. */
-
- leap_yrs = ((*pyear - 1900)/4) + 1;
- if ((*pyear % 4 == 0) && (*pmonth <= 2)) /* Not February 29 yet */
- leap_yrs--;
- day_index = ((day_offset[*pmonth] + *pday + (*pyear - 1900)
- + leap_yrs) % 7);
-
- sprintf(pdate,"%s %s %d, %d",day_name[day_index],
- month_name[*pmonth],
- *pday,
- *pyear);
- return(0);
- }