1 64bcfff3 2003-11-25 devnull #define NOPLAN9DEFINES
2 5db07ba9 2006-03-03 devnull #include <u.h>
3 fd04aace 2003-11-23 devnull #include <libc.h>
4 5db07ba9 2006-03-03 devnull #include <stdlib.h> /* setenv etc. */
5 64bcfff3 2003-11-25 devnull #include <time.h>
7 5db07ba9 2006-03-03 devnull static int didtz;
8 5db07ba9 2006-03-03 devnull static int tzdelta;
9 5db07ba9 2006-03-03 devnull static char tzone[4];
11 5db07ba9 2006-03-03 devnull static void
12 5db07ba9 2006-03-03 devnull dotz(void)
14 5db07ba9 2006-03-03 devnull time_t t;
16 5db07ba9 2006-03-03 devnull if(didtz)
18 5db07ba9 2006-03-03 devnull t = time(0);
19 5db07ba9 2006-03-03 devnull tzdelta = t - mktime(gmtime(&t));
20 5db07ba9 2006-03-03 devnull strftime(tzone, sizeof tzone, "%Z", localtime(&t));
23 fd04aace 2003-11-23 devnull static void
24 5db07ba9 2006-03-03 devnull tm2Tm(struct tm *tm, Tm *bigtm, int gmt)
26 fd04aace 2003-11-23 devnull memset(bigtm, 0, sizeof *bigtm);
27 fd04aace 2003-11-23 devnull bigtm->sec = tm->tm_sec;
28 fd04aace 2003-11-23 devnull bigtm->min = tm->tm_min;
29 fd04aace 2003-11-23 devnull bigtm->hour = tm->tm_hour;
30 fd04aace 2003-11-23 devnull bigtm->mday = tm->tm_mday;
31 fd04aace 2003-11-23 devnull bigtm->mon = tm->tm_mon;
32 fd04aace 2003-11-23 devnull bigtm->year = tm->tm_year;
33 fd04aace 2003-11-23 devnull bigtm->wday = tm->tm_wday;
35 5db07ba9 2006-03-03 devnull strcpy(bigtm->zone, "GMT");
36 5db07ba9 2006-03-03 devnull bigtm->tzoff = 0;
39 5db07ba9 2006-03-03 devnull strcpy(bigtm->zone, tzone);
40 5db07ba9 2006-03-03 devnull bigtm->tzoff = tzdelta;
44 fd04aace 2003-11-23 devnull static void
45 fd04aace 2003-11-23 devnull Tm2tm(Tm *bigtm, struct tm *tm)
47 fd04aace 2003-11-23 devnull memset(tm, 0, sizeof *tm);
48 fd04aace 2003-11-23 devnull tm->tm_sec = bigtm->sec;
49 fd04aace 2003-11-23 devnull tm->tm_min = bigtm->min;
50 fd04aace 2003-11-23 devnull tm->tm_hour = bigtm->hour;
51 fd04aace 2003-11-23 devnull tm->tm_mday = bigtm->mday;
52 fd04aace 2003-11-23 devnull tm->tm_mon = bigtm->mon;
53 fd04aace 2003-11-23 devnull tm->tm_year = bigtm->year;
54 fd04aace 2003-11-23 devnull tm->tm_wday = bigtm->wday;
58 829e8223 2004-12-29 devnull p9gmtime(long x)
60 829e8223 2004-12-29 devnull time_t t;
61 fd04aace 2003-11-23 devnull struct tm tm;
62 5db07ba9 2006-03-03 devnull static Tm bigtm;
64 829e8223 2004-12-29 devnull t = (time_t)x;
65 fd04aace 2003-11-23 devnull tm = *gmtime(&t);
66 5db07ba9 2006-03-03 devnull tm2Tm(&tm, &bigtm, 1);
67 fd04aace 2003-11-23 devnull return &bigtm;
71 829e8223 2004-12-29 devnull p9localtime(long x)
73 829e8223 2004-12-29 devnull time_t t;
74 fd04aace 2003-11-23 devnull struct tm tm;
75 5db07ba9 2006-03-03 devnull static Tm bigtm;
77 829e8223 2004-12-29 devnull t = (time_t)x;
78 fd04aace 2003-11-23 devnull tm = *localtime(&t);
79 5db07ba9 2006-03-03 devnull tm2Tm(&tm, &bigtm, 0);
80 fd04aace 2003-11-23 devnull return &bigtm;
84 fd04aace 2003-11-23 devnull p9tm2sec(Tm *bigtm)
86 5db07ba9 2006-03-03 devnull time_t t;
87 fd04aace 2003-11-23 devnull struct tm tm;
89 fd04aace 2003-11-23 devnull Tm2tm(bigtm, &tm);
90 5db07ba9 2006-03-03 devnull t = mktime(&tm);
91 5db07ba9 2006-03-03 devnull if(strcmp(bigtm->zone, "GMT") == 0 || strcmp(bigtm->zone, "UCT") == 0){
93 5db07ba9 2006-03-03 devnull t += tzdelta;
95 5db07ba9 2006-03-03 devnull return t;