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

  1. /**
  2. *
  3. * Name        drstp2dt -- Convert date stamp to date
  4. *
  5. * Synopsis    ercode = drstp2dt(fdate,pyear,pmonth,pday);
  6. *
  7. *        int ercode      Error code is -1 if date stamp
  8. *                  is not a legal date, 0 if o.k.
  9. *        unsigned fdate      16-bit date stamp.
  10. *        int *pyear,*pmonth,*pday  Pointers to variables in which
  11. *                  the year, month, and day are returned.
  12. *
  13. * Description    This function converts a calendar date from the DOS
  14. *        directory date stamp format into separate year, month,
  15. *        and day.
  16. *
  17. *        The date stamp (fdate) is a date of the year 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. *              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 DRDT2STP to convert a date into this date stamp
  31. *        format.  Use DRTM2STP or DRSTP2TM to convert time
  32. *        stamps.
  33. *
  34. * Returns    ercode               Returned error code
  35. *        *pyear,*pmonth,*pday   The date as numeric values.
  36. *
  37. * Version    3.0 (C)Copyright Blaise Computing Inc. 1986
  38. *
  39. **/
  40.  
  41. #include <bdirect.h>
  42. #include <butility.h>
  43.  
  44. int drstp2dt(fdate,pyear,pmonth,pday)
  45. unsigned fdate;
  46. int     *pyear,*pmonth,*pday;
  47. {
  48.     *pyear  = (fdate >> 9)     + 1980;
  49.     *pmonth = (fdate >> 5) & 0x0f;
  50.     *pday   =  fdate       & 0x1f;
  51.  
  52.     if (   utrange(*pyear,1900,2099)
  53.     || utrange(*pmonth,1,12)
  54.     || utrange(*pday,1,31))
  55.     return(-1);              /* Date is out of range.          */
  56.  
  57.     return 0;                  /* Success.              */
  58. }
  59.