home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / metamail / contrib / ServiceMail / src / pdinq / getdate / getdate.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-15  |  1.1 KB  |  63 lines

  1. #include "dateconv.h"
  2. #include "datelex.h"
  3.  
  4. time_t getdate(p, now) char *p; struct timeb *now;
  5. {
  6. #define mcheck(f)    if (f>1) err++
  7.     time_t monthadd();
  8.     int err;
  9.     struct tm *lt;
  10.     struct timeb ftz;
  11.  
  12.     time_t sdate, tod;
  13.  
  14.     lptr = p;
  15.     if (now == ((struct timeb *) NULL)) {
  16.         now = &ftz;
  17.         ftime(&ftz);
  18.     }
  19.     lt = localtime(&now->time);
  20.     year = lt->tm_year;
  21.     month = lt->tm_mon+1;
  22.     day = lt->tm_mday;
  23.     relsec = 0; relmonth = 0;
  24.     timeflag=zoneflag=dateflag=dayflag=relflag=0;
  25.     ourzone = now->timezone / 60;
  26.     daylight = MAYBE;
  27.     hh = mm = ss = 0;
  28.     merid = 24;
  29.  
  30.     if (err = yyparse()) return (-1);
  31.  
  32.     mcheck(timeflag);
  33.     mcheck(zoneflag);
  34.     mcheck(dateflag);
  35.     mcheck(dayflag);
  36.  
  37.     if (err) return (-1);
  38.  
  39.     if (dateflag || timeflag || dayflag) {
  40.         sdate = dateconv(month,day,year,hh,mm,ss,merid,ourzone,daylight);
  41.         if (sdate < 0) return -1;
  42.     }
  43.     else {
  44.         sdate = now->time;
  45.         if (relflag == 0)
  46.             sdate -= (lt->tm_sec + lt->tm_min*60 +
  47.                 lt->tm_hour*(60L*60L));
  48.     }
  49.  
  50.     sdate += relsec;
  51.     sdate += monthadd(sdate, relmonth);
  52.  
  53.     if (dayflag) {
  54.         tod = dayconv(dayord, dayreq, sdate);
  55.         sdate += tod;
  56.     }
  57.     
  58.     return sdate;
  59. }
  60.  
  61. yyerror(s) char *s;
  62. {}
  63.