home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 328_02 / wmktime.c < prev    next >
C/C++ Source or Header  |  1991-03-17  |  2KB  |  70 lines

  1. /* mktime.c
  2.  *
  3.  *    mktime  () - the ANSI time routine that TurboC forgot.
  4.  *                   time_t mktime (struct tm *ts) - convert struct to time_t
  5.  *    
  6.  *    This routine not needed for TurboC++
  7.  *    
  8.  *  BEWARE!!!
  9.  *        ANSI struct tm, year= yrs since 1900 (0 and up)
  10.  *                      mon = mons since Jan (0-11)
  11.  *                        day = day of the month (1-31) 
  12.  *                        h.m.s all start at 0.
  13.  *
  14.  *        ANSI time_t     value is # seconds since 1/1/1970
  15.  *
  16.  *        DOS  struct time - h, m, s all start at 0.
  17.  *        DOS  struct date - da_day runs 1-31, da_mon 1-12, da_year 1970=1970
  18.  *
  19.  *    ALSO - beware - this routine does not modify the caller's versions
  20.  *            as the real UNIX version does.
  21.  */
  22.  
  23. #ifdef __TURBOC__
  24.  
  25.  
  26.  
  27. #include "wsys.h"
  28.  
  29.  
  30. /* The ANSI standard time routine that TurboC forgot.
  31.  * Present in Microsoft - my grudging acknowledgement of one advantage of MSC
  32.  */
  33. time_t     mktime ( struct tm *tmp )
  34.     {
  35.     time_t t;
  36.     struct time    dost;
  37.     struct date    dosd;
  38.  
  39.     dost.ti_min  = tmp->tm_min;
  40.     dost.ti_hour = tmp->tm_hour;
  41.     dost.ti_sec  = tmp->tm_sec;
  42.     dost.ti_hund = 0;
  43.     dosd.da_year = tmp->tm_year + 1900;    /* ANSI 0=1900, DOS 0=0 */
  44.     dosd.da_day  = tmp->tm_mday;
  45.     dosd.da_mon  = tmp->tm_mon +  1;    /* ANSI 0=JAN   DOS 1=JAN */
  46.  
  47.  
  48.     t = dostounix (  &dosd, &dost );
  49.  
  50.  
  51. #if 0    
  52.     /* the ANSI version of mktime() adjusts the caller's values
  53.      *    but this isn't needed for our purposes, so omit for efficiency
  54.      */
  55.  
  56.     unixtodos ( t, &dosd, &dost );        /* re-adjust callers values */
  57.     
  58.     tmp->tm_min  = dost.ti_min;
  59.     tmp->tm_hour = dost.ti_hour;
  60.     tmp->tm_sec  = dost.ti_sec;
  61.     tmp->tm_year = dosd.da_year - 1900;    /* ANSI 0=1900, DOS 0=0 */
  62.     tmp->tm_mday = dosd.da_day;
  63.     tmp->tm_mon  = dosd.da_mon - 1;    /* ANSI 0=JAN   DOS 1=JAN */
  64. #endif
  65.  
  66.  
  67.     return ( t );
  68.     }
  69. #endif /* __TURBOC__ */
  70.