summaryrefslogtreecommitdiffstats
path: root/src/lib9/date.c
diff options
context:
space:
mode:
authorMichael Teichgräber <devnull@localhost>2008-07-09 08:27:22 -0400
committerMichael Teichgräber <devnull@localhost>2008-07-09 08:27:22 -0400
commitf35a04866f298aa4b0fa6846da0c0187751ce9b2 (patch)
treeaa4b87fbc1f71b246c9c8975abb0cab936f7ef2b /src/lib9/date.c
parent1cccddd6b3fb4a90641b8d05dc0bed618380074c (diff)
downloadplan9port-f35a04866f298aa4b0fa6846da0c0187751ce9b2.tar.gz
plan9port-f35a04866f298aa4b0fa6846da0c0187751ce9b2.zip
lib9: rewrite date routines to use /usr/share/zoneinfo directly
Diffstat (limited to 'src/lib9/date.c')
-rw-r--r--src/lib9/date.c100
1 files changed, 0 insertions, 100 deletions
diff --git a/src/lib9/date.c b/src/lib9/date.c
deleted file mode 100644
index 8509bb48..00000000
--- a/src/lib9/date.c
+++ /dev/null
@@ -1,100 +0,0 @@
-#define NOPLAN9DEFINES
-#include <u.h>
-#include <libc.h>
-#include <stdlib.h> /* setenv etc. */
-#include <time.h>
-
-static int
-dotz(time_t t, char *tzone)
-{
- struct tm *gtm;
- struct tm tm;
-
- strftime(tzone, 32, "%Z", localtime(&t));
- tm = *localtime(&t); /* set local time zone field */
- gtm = gmtime(&t);
- tm.tm_sec = gtm->tm_sec;
- tm.tm_min = gtm->tm_min;
- tm.tm_hour = gtm->tm_hour;
- tm.tm_mday = gtm->tm_mday;
- tm.tm_mon = gtm->tm_mon;
- tm.tm_year = gtm->tm_year;
- tm.tm_wday = gtm->tm_wday;
- return t - mktime(&tm);
-}
-
-static void
-tm2Tm(struct tm *tm, Tm *bigtm, int tzoff, char *zone)
-{
- memset(bigtm, 0, sizeof *bigtm);
- bigtm->sec = tm->tm_sec;
- bigtm->min = tm->tm_min;
- bigtm->hour = tm->tm_hour;
- bigtm->mday = tm->tm_mday;
- bigtm->mon = tm->tm_mon;
- bigtm->year = tm->tm_year;
- bigtm->wday = tm->tm_wday;
- bigtm->tzoff = tzoff;
- strncpy(bigtm->zone, zone, 3);
- bigtm->zone[3] = 0;
-}
-
-static void
-Tm2tm(Tm *bigtm, struct tm *tm)
-{
- /* initialize with current time to get local time zone! (tm_isdst) */
- time_t t;
- time(&t);
- *tm = *localtime(&t);
-
- tm->tm_sec = bigtm->sec;
- tm->tm_min = bigtm->min;
- tm->tm_hour = bigtm->hour;
- tm->tm_mday = bigtm->mday;
- tm->tm_mon = bigtm->mon;
- tm->tm_year = bigtm->year;
- tm->tm_wday = bigtm->wday;
-}
-
-Tm*
-p9gmtime(long x)
-{
- time_t t;
- struct tm tm;
- static Tm bigtm;
-
- t = (time_t)x;
- tm = *gmtime(&t);
- tm2Tm(&tm, &bigtm, 0, "GMT");
- return &bigtm;
-}
-
-Tm*
-p9localtime(long x)
-{
- time_t t;
- struct tm tm;
- static Tm bigtm;
- char tzone[32];
-
- t = (time_t)x;
- tm = *localtime(&t);
- tm2Tm(&tm, &bigtm, dotz(t, tzone), tzone);
- return &bigtm;
-}
-
-long
-p9tm2sec(Tm *bigtm)
-{
- time_t t;
- struct tm tm;
- char tzone[32];
-
- Tm2tm(bigtm, &tm);
- t = mktime(&tm);
- if(strcmp(bigtm->zone, "GMT") == 0 || strcmp(bigtm->zone, "UCT") == 0){
- t += dotz(t, tzone);
- }
- return t;
-}
-