File: datetime.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 (55 lines) | stat: -rw-r--r-- 1,136 bytes parent folder | download | duplicates (16)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* 19950925 */
#include "datetime.h"

void datetime_tai(dt,t)
struct datetime *dt;
datetime_sec t;
{
  int day;
  int tod;
  int year;
  int yday;
  int wday;
  int mon;
 
  tod = t % 86400;
  day = t / 86400;
  if (tod < 0) { tod += 86400; --day; }
 
  dt->hour = tod / 3600;
  tod %= 3600;
  dt->min = tod / 60;
  dt->sec = tod % 60;
 
  wday = (day + 4) % 7; if (wday < 0) wday += 7;
  dt->wday = wday;
 
  day -= 11017;
  /* day 0 is march 1, 2000 */
  year = 5 + day / 146097;
  day = day % 146097; if (day < 0) { day += 146097; --year; }
  /* from now on, day is nonnegative */
  year *= 4;
  if (day == 146096) { year += 3; day = 36524; }
  else { year += day / 36524; day %= 36524; }
  year *= 25;
  year += day / 1461;
  day %= 1461;
  year *= 4;
  yday = (day < 306);
  if (day == 1460) { year += 3; day = 365; }
  else { year += day / 365; day %= 365; }
  yday += day;
 
  day *= 10;
  mon = (day + 5) / 306;
  day = day + 5 - 306 * mon;
  day /= 10;
  if (mon >= 10) { yday -= 306; ++year; mon -= 10; }
  else { yday += 59; mon += 2; }
 
  dt->yday = yday;
  dt->year = year - 1900;
  dt->mon = mon;
  dt->mday = day + 1;
}