home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_02 / 1102027a < prev    next >
Text File  |  1992-12-09  |  840b  |  36 lines

  1. /* mktime function */
  2. #include <limits.h>
  3. #include "xtime.h"
  4.  
  5. time_t (mktime)(struct tm *t)
  6.     {    /* convert local time structure
  7.             to scalar time */
  8.     double dsecs;
  9.     int mon, year, ymon;
  10.     time_t secs;
  11.  
  12.     ymon = t->tm_mon / 12;
  13.     mon = t->tm_mon - ymon * 12;
  14.     if (mon < 0)
  15.         mon += 12, --ymon;
  16.     if (ymon < 0 && t->tm_year < INT_MIN - ymon
  17.         || 0 < ymon && INT_MAX - ymon < t->tm_year)
  18.         return ((time_t)(-1));
  19.     year = t->tm_year + ymon;
  20.     dsecs = 86400.0 * (_Daysto(year, mon) - 1)
  21.         + 31536000.0 * year + 86400.0 * t->tm_mday;
  22.     dsecs += 3600.0 * t->tm_hour + 60.0 * t->tm_min
  23.         + (double)t->tm_sec;
  24.     if (dsecs < 0.0 || (double)(time_t)(-1) <= dsecs)
  25.         return ((time_t)(-1));
  26.     secs = (time_t)dsecs - _TBIAS;
  27.     _Ttotm(t, secs, t->tm_isdst);
  28.     if (0 < t->tm_isdst)
  29.         secs -= 3600;
  30.     return (secs - _Tzoff());
  31.     }
  32.  
  33.  
  34.  
  35.  
  36.