File: nv_gmtime.c

package info (click to toggle)
ngetty 1.0-1
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 304 kB
  • ctags: 207
  • sloc: ansic: 1,503; makefile: 236; sh: 109; asm: 100
file content (36 lines) | stat: -rw-r--r-- 840 bytes parent folder | download | duplicates (5)
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
#include <time.h>

struct tm *nv_gmtime(const time_t *t) /*EXTRACT_INCL*/{
  static struct tm tm;
  unsigned long day, mon, year, yday=0, tod;

  tod = (unsigned long)(*t) % 86400;
  day = (unsigned long)(*t) / 86400;
  tm.tm_wday = ((day+4) % 7);
  tm.tm_sec  = tod%60; tod /= 60;
  tm.tm_min  = tod%60; 
  tm.tm_hour = tod/60;

  year = 4*day + 2;
  year /= 1461;

  day += 671;
  day %= 1461;           /* day 0 is march 1, 1972 */
  if (day < 306) yday = 1;
  if (day == 1460) { day = 365; yday = 59; }
  else { day %= 365;   yday += (day + 59) % 365; }

  day *= 10;
  mon = (day + 5) / 306;
  day = day + 5 - 306 * mon;
  day /= 10;
  if (mon >= 10) mon -= 10;
  else mon += 2;      /* day 0,1,30, mon 0..11,  year 1970=0,1,2 */

  tm.tm_year = year+70;
  tm.tm_mon  = mon;
  tm.tm_mday = day+1;
  tm.tm_yday = yday;
  return &tm;
}