home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 5.ddi / C / STSTIME.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  2.2 KB  |  80 lines

  1. /**
  2. *
  3. * Name        ststime -- Return the system time in USA format
  4. *
  5. * Synopsis    ercode = ststime(ptime,phours,pminutes,pseconds,phunds);
  6. *
  7. *        int ercode      Return code is -1 if an illegal system
  8. *                  time is found; otherwise 0 is returned.
  9. *        char *ptime      Pointer to string in which time is returned.
  10. *                  The string should be large enough to
  11. *                  contain 8 characters plus the trailing
  12. *                  NUL ('\0').
  13. *        int *phours,*pminutes,*pseconds,*phunds
  14. *                  Pointers to integers in which the time
  15. *                  is returned as numeric values.
  16. *
  17. * Description    STSTIME returns the system time both as a string of the
  18. *        form HH:MM AM or PM and as the numeric values for hours,
  19. *        minutes, seconds, and hundredths of seconds.  If the
  20. *        system time is not a legal value, -1 is returned as the
  21. *        function value and ptime is the null string.
  22. *
  23. *        Note:  The time string is NOT rounded to the nearest
  24. *        minute -- the seconds are just dropped.
  25. *
  26. * Returns    int ercode      Returned status code.
  27. *        char *ptime      Time string in the form HH:MM AM or PM.
  28. *        int *phours,*pminutes,*pseconds,*phunds
  29. *                  The time as numeric values
  30. *
  31. * Version    3.0 (C)Copyright Blaise Computing Inc.    1983, 1984, 1985, 1986
  32. *
  33. **/
  34.  
  35. #include <stdio.h>
  36.  
  37. #include <bstring.h>
  38.  
  39. int ststime(ptime,phours,pminutes,pseconds,phunds)
  40. char          *ptime;
  41. int          *phours;
  42. register int  *pminutes;
  43. int          *pseconds,*phunds;
  44. {
  45.     register int  hours;          /* Altered value for string     */
  46.     register int  am;              /* AM/PM flag              */
  47.  
  48.     qyrettim(phours,pminutes,          /* Recover the time          */
  49.          pseconds,phunds);
  50.     hours = *phours;
  51.  
  52.     if (utrange(hours,0,23) || utrange(*pminutes,0,59) ||
  53.          utrange(*pseconds,0,59) || utrange(*phunds,0,99))
  54.     {
  55.        *ptime = '\0';
  56.        return(-1);              /* Illegal system time          */
  57.     }
  58.  
  59.     if (hours < 12)              /* Set the AM or PM flag          */
  60.     {
  61.        am = 1;
  62.        if (hours == 0)
  63.       hours = 12;              /* Midnight              */
  64.     }
  65.     else
  66.     {
  67.        am = 0;
  68.        if (hours > 12)
  69.       hours -= 12;
  70.     }
  71.  
  72.     /* Now put the pieces together to construct the string.          */
  73.  
  74.     sprintf(ptime,"%2d:%02d %cM",hours,
  75.                  *pminutes,
  76.                  am ? 'A' : 'P');
  77.  
  78.     return(0);
  79. }
  80.