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

  1. /**
  2. *
  3. * Name        drtm2stp -- Convert time of day to time stamp
  4. *
  5. * Synopsis    ercode = drtm2stp(pftime,hour,minute,second);
  6. *
  7. *        int ercode      Error code is -1 if time of day
  8. *                  is not a legal time, 0 if okay.
  9. *        unsigned *pftime  Pointer to resulting 16-bit time stamp.
  10. *        int hour      Hour of the day (0-23)
  11. *        int minute      Minute of the hour (0-59)
  12. *        int second      Second of the minute (0-59)
  13. *
  14. * Description    This function converts a time of day into the DOS
  15. *        directory time stamp format.
  16. *
  17. *        The time stamp (*pftime) is a time of day packed into
  18. *        the following format:
  19. *
  20. *              **********   bits   ***********
  21. *              1 1 1 1 1 1
  22. *              5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  23. *
  24. *              h h h h h m m m m m m s s s s s    = ftime
  25. *
  26. *        where the second bits represent two-second increments.
  27. *        This is the same format used by DRRETSTP, DRSETSTP,
  28. *        DRSFIRST, and DRSNEXT.
  29. *
  30. *        Use DRSTP2TM to split a time stamp into separate hour,
  31. *        minute, and second values.  Use DRDT2STP or DRSTP2DT to
  32. *        convert date stamps.
  33. *
  34. * Returns    ercode          Returned error code (-1 if illegal time,
  35. *                  0 if okay).
  36. *        *pftime       Resulting 16-bit time stamp (0 if error).
  37. *
  38. * Version    3.0 (C)Copyright Blaise Computing Inc. 1986
  39. *
  40. **/
  41.  
  42. #include <bdirect.h>
  43. #include <butility.h>
  44.  
  45. int drtm2stp(pftime,hour,minute,second)
  46. unsigned *pftime;
  47. int     hour,minute,second;
  48. {
  49.     if (   utrange(hour,  0,23)
  50.     || utrange(minute,0,59)
  51.     || utrange(second,0,59))
  52.     {
  53.     *pftime = 0;
  54.     return(-1);              /* Time is out of range.          */
  55.     }
  56.     *pftime = (hour << 11) | (minute << 5) | (second >> 1);
  57.     return 0;
  58. }
  59.