home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name ststime -- Return the system time in USA format
- *
- * Synopsis ercode = ststime(ptime,phours,pminutes,pseconds,phunds);
- *
- * int ercode Return code is -1 if an illegal system
- * time is found; otherwise 0 is returned.
- * char *ptime Pointer to string in which time is returned.
- * The string should be large enough to
- * contain 8 characters plus the trailing
- * NUL ('\0').
- * int *phours,*pminutes,*pseconds,*phunds
- * Pointers to integers in which the time
- * is returned as numeric values.
- *
- * Description STSTIME returns the system time both as a string of the
- * form HH:MM AM or PM and as the numeric values for hours,
- * minutes, seconds, and hundredths of seconds. If the
- * system time is not a legal value, -1 is returned as the
- * function value and ptime is the null string.
- *
- * Note: The time string is NOT rounded to the nearest
- * minute -- the seconds are just dropped.
- *
- * Returns int ercode Returned status code.
- * char *ptime Time string in the form HH:MM AM or PM.
- * int *phours,*pminutes,*pseconds,*phunds
- * The time as numeric values
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1983, 1984, 1985, 1986
- *
- **/
-
- #include <stdio.h>
-
- #include <bstring.h>
-
- int ststime(ptime,phours,pminutes,pseconds,phunds)
- char *ptime;
- int *phours;
- register int *pminutes;
- int *pseconds,*phunds;
- {
- register int hours; /* Altered value for string */
- register int am; /* AM/PM flag */
-
- qyrettim(phours,pminutes, /* Recover the time */
- pseconds,phunds);
- hours = *phours;
-
- if (utrange(hours,0,23) || utrange(*pminutes,0,59) ||
- utrange(*pseconds,0,59) || utrange(*phunds,0,99))
- {
- *ptime = '\0';
- return(-1); /* Illegal system time */
- }
-
- if (hours < 12) /* Set the AM or PM flag */
- {
- am = 1;
- if (hours == 0)
- hours = 12; /* Midnight */
- }
- else
- {
- am = 0;
- if (hours > 12)
- hours -= 12;
- }
-
- /* Now put the pieces together to construct the string. */
-
- sprintf(ptime,"%2d:%02d %cM",hours,
- *pminutes,
- am ? 'A' : 'P');
-
- return(0);
- }