home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Unix / CNews / Source / libc / dateconv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-10  |  889 b   |  36 lines

  1. /*
  2.  * dateconv - convert a split-out date back into a time_t
  3.  */
  4.  
  5. #include <time.h>
  6. #include <sys/types.h>
  7. #include <sys/timeb.h>
  8.  
  9. /* imports */
  10. extern time_t qmktime();
  11.  
  12. /* turn a (struct tm) and a few variables into a time_t, with range checking */
  13. time_t
  14. dateconv(tm, zone)
  15. register struct tm *tm;
  16. int zone;
  17. {
  18.     tm->tm_wday = tm->tm_yday = 0;
  19.  
  20.     /* validate, before going out of range on some members */
  21.     if (tm->tm_year < 0 || tm->tm_mon < 0 || tm->tm_mon > 11 ||
  22.         tm->tm_mday < 1 || tm->tm_hour < 0 || tm->tm_hour >= 24 ||
  23.         tm->tm_min < 0 || tm->tm_min > 59 ||
  24.         tm->tm_sec < 0 || tm->tm_sec > 61)    /* allow 2 leap seconds */
  25.         return -1;
  26.  
  27.     /*
  28.      * zone should really be -zone, and tz should be set to tp->value, not
  29.      * -tp->value.  Or the table could be fixed.
  30.      */
  31.     tm->tm_min += zone;        /* mktime lets it be out of range */
  32.  
  33.     /* convert to seconds */
  34.     return qmktime(tm);
  35. }
  36.