home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume11 / mtools / part01 / convdate.c next >
Text File  |  1987-08-27  |  1KB  |  63 lines

  1. /*
  2.  * convdate(), convtime()
  3.  */
  4.  
  5. /*
  6.  * convert MSDOS directory datestamp to ASCII
  7.  */
  8.  
  9. char *
  10. convdate(date_high, date_low)
  11. unsigned date_high;
  12. unsigned date_low;
  13. {
  14. /*
  15.  *        hi byte     |    low byte
  16.  *    |0|1|2|3|4|5|6|7|0|1|2|3|4|5|6|7|
  17.  *      | | | | | | | | | | | | | | | | |
  18.  *      \   7 bits    /\4 bits/\ 5 bits /
  19.  *         year +80      month     day
  20.  */
  21.     static char buffer[9];
  22.     unsigned char year, month_hi, month_low, day;
  23.  
  24.     year = (date_high >> 1) + 80;
  25.     month_hi = (date_high & 0x1) << 3;
  26.     month_low = date_low >> 5;
  27.     day = date_low & 0x1f;
  28.     sprintf(buffer, "%2d-%02d-%02d", month_hi+month_low, day, year);
  29.     return(buffer);
  30. }
  31.  
  32. /*
  33.  * Convert MSDOS directory timestamp to ASCII
  34.  */
  35.  
  36. char *
  37. convtime(time_high, time_low)
  38. unsigned time_high;
  39. unsigned time_low;
  40. {
  41. /*
  42.  *        hi byte     |    low byte
  43.  *    |0|1|2|3|4|5|6|7|0|1|2|3|4|5|6|7|
  44.  *      | | | | | | | | | | | | | | | | |
  45.  *      \  5 bits /\  6 bits  /\ 5 bits /
  46.  *         hour      minutes     sec*2
  47.  */
  48.     static char buffer[7];
  49.     char am_pm;
  50.     unsigned char hour, min_hi, min_low;
  51.  
  52.     hour = time_high >> 3;
  53.     am_pm = (hour >= 12) ? 'p' : 'a';
  54.     if (hour > 12)
  55.         hour = hour -12;
  56.     if (hour == 0)
  57.         hour = 12;
  58.     min_hi = (time_high & 0x7) << 3;
  59.     min_low = time_low >> 5;
  60.     sprintf(buffer, "%2d:%02d%c", hour, min_hi+min_low, am_pm);
  61.     return(buffer);
  62. }
  63.