File: datetime_un.c

package info (click to toggle)
qmail 1.01-5
  • links: PTS
  • area: non-free
  • in suites: hamm
  • size: 2,188 kB
  • ctags: 1,711
  • sloc: ansic: 13,993; makefile: 1,914; perl: 448; sh: 377
file content (35 lines) | stat: -rw-r--r-- 678 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "datetime.h"

/* roughly 100x faster than mktime() */
datetime_sec datetime_untai(dt)
struct datetime *dt;
{
  int year;
  int day;
  int mon;
 
  year = dt->year + 1900;
 
  mon = dt->mon;
  if (mon >= 2) { mon -= 2; }
  else { mon += 10; --year; }
 
  day = (dt->mday - 1) * 10 + 5 + 306 * mon;
  day /= 10;
 
  if (day == 365) { year -= 3; day = 1460; }
  else { day += 365 * (year % 4); }
  year /= 4;
 
  day += 1461 * (year % 25);
  year /= 25;
 
  if (day == 36524) { year -= 3; day = 146096; }
  else { day += 36524 * (year % 4); }
  year /= 4;
 
  day += 146097 * (year - 5);
  day += 11017;
 
  return ((day * 24 + dt->hour) * 60 + dt->min) * 60 + dt->sec;
}