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

  1. /**
  2. *
  3. * Name        drdt2stp -- Convert date to date stamp
  4. *
  5. * Synopsis    ercode = drdt2stp(pfdate,year,month,day);
  6. *
  7. *        int ercode      Error code is -1 if day of year
  8. *                  is not a legal date, 0 if okay.
  9. *        unsigned *pftime  Pointer to resulting 16-bit date stamp.
  10. *        int year      Year (1980 to 2099)
  11. *        int month      Month (1 to 12)
  12. *        int day       Day of the month (1 to 31)
  13. *
  14. * Description    This function converts a date into the DOS directory
  15. *        date stamp format.
  16. *
  17. *        The date stamp (*pfdate) is a date of the year packed
  18. *        into 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. *              y y y y y y y m m m m d d d d d    = fdate
  25. *
  26. *        where the year bits represent 0 - 119 (1980 to 2099).
  27. *        This is the same format used by DRRETSTP, DRSETSTP,
  28. *        DRSFIRST, and DRSNEXT.
  29. *
  30. *        Use DRSTP2DT to split a date stamp into separate year,
  31. *        month, and day values.    Use DRDT2STP or DRSTP2DT to
  32. *        convert date stamps.
  33. *
  34. * Returns    ercode          Returned error code (-1 if illegal date,
  35. *                  0 if okay).
  36. *        *pfdate       Resulting 16-bit date 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 drdt2stp(pfdate,year,month,day)
  46. unsigned *pfdate;
  47. int     year,month,day;
  48. {
  49.     if (   utrange(year, 1980,2099)
  50.     || utrange(month,   1,    12)
  51.     || utrange(day,     1,    31))
  52.     {
  53.     *pfdate = 0;
  54.     return(-1);              /* Date is out of range.          */
  55.     }
  56.     *pfdate = ((year - 1980) << 9) | (month << 5) | day;
  57.     return 0;
  58. }
  59.