nightmaremail

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

datetime.c (1136B)


      1 /* 19950925 */
      2 #include "datetime.h"
      3 
      4 void datetime_tai(dt,t)
      5 struct datetime *dt;
      6 datetime_sec t;
      7 {
      8   int day;
      9   int tod;
     10   int year;
     11   int yday;
     12   int wday;
     13   int mon;
     14  
     15   tod = t % 86400;
     16   day = t / 86400;
     17   if (tod < 0) { tod += 86400; --day; }
     18  
     19   dt->hour = tod / 3600;
     20   tod %= 3600;
     21   dt->min = tod / 60;
     22   dt->sec = tod % 60;
     23  
     24   wday = (day + 4) % 7; if (wday < 0) wday += 7;
     25   dt->wday = wday;
     26  
     27   day -= 11017;
     28   /* day 0 is march 1, 2000 */
     29   year = 5 + day / 146097;
     30   day = day % 146097; if (day < 0) { day += 146097; --year; }
     31   /* from now on, day is nonnegative */
     32   year *= 4;
     33   if (day == 146096) { year += 3; day = 36524; }
     34   else { year += day / 36524; day %= 36524; }
     35   year *= 25;
     36   year += day / 1461;
     37   day %= 1461;
     38   year *= 4;
     39   yday = (day < 306);
     40   if (day == 1460) { year += 3; day = 365; }
     41   else { year += day / 365; day %= 365; }
     42   yday += day;
     43  
     44   day *= 10;
     45   mon = (day + 5) / 306;
     46   day = day + 5 - 306 * mon;
     47   day /= 10;
     48   if (mon >= 10) { yday -= 306; ++year; mon -= 10; }
     49   else { yday += 59; mon += 2; }
     50  
     51   dt->yday = yday;
     52   dt->year = year - 1900;
     53   dt->mon = mon;
     54   dt->mday = day + 1;
     55 }