nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

datetime_un.c (678B)


      1 #include "datetime.h"
      2 
      3 /* roughly 100x faster than mktime() */
      4 datetime_sec datetime_untai(dt)
      5 struct datetime *dt;
      6 {
      7   int year;
      8   int day;
      9   int mon;
     10  
     11   year = dt->year + 1900;
     12  
     13   mon = dt->mon;
     14   if (mon >= 2) { mon -= 2; }
     15   else { mon += 10; --year; }
     16  
     17   day = (dt->mday - 1) * 10 + 5 + 306 * mon;
     18   day /= 10;
     19  
     20   if (day == 365) { year -= 3; day = 1460; }
     21   else { day += 365 * (year % 4); }
     22   year /= 4;
     23  
     24   day += 1461 * (year % 25);
     25   year /= 25;
     26  
     27   if (day == 36524) { year -= 3; day = 146096; }
     28   else { day += 36524 * (year % 4); }
     29   year /= 4;
     30  
     31   day += 146097 * (year - 5);
     32   day += 11017;
     33  
     34   return ((day * 24 + dt->hour) * 60 + dt->min) * 60 + dt->sec;
     35 }