cure cancer
[unix-history] / usr / src / lib / libc / gen / timezone.c
CommitLineData
6114b84d 1/* @(#)timezone.c 4.4 (Berkeley) %G% */
9d342dd9
BJ
2/*
3 * The arguments are the number of minutes of time
4 * you are westward from Greenwich and whether DST is in effect.
5 * It returns a string
6 * giving the name of the local timezone.
7 *
8 * Sorry, I don't know all the names.
9 */
10
11static struct zone {
12 int offset;
13 char *stdzone;
14 char *dlzone;
15} zonetab[] = {
6114b84d
MK
16 -1*60, "MET", "MET DST", /* Middle European */
17 -2*60, "EET", "EET DST", /* Eastern European */
9d342dd9
BJ
18 4*60, "AST", "ADT", /* Atlantic */
19 5*60, "EST", "EDT", /* Eastern */
20 6*60, "CST", "CDT", /* Central */
21 7*60, "MST", "MDT", /* Mountain */
22 8*60, "PST", "PDT", /* Pacific */
7f253f66
SL
23#ifdef notdef
24 /* there's no way to distinguish this from WET */
9d342dd9 25 0, "GMT", 0, /* Greenwich */
7f253f66
SL
26#endif
27 0*60, "WET", "WET DST", /* Western European */
bdea7503
SL
28 -10*60, "EST", "EST", /* Aust: Eastern */
29 -10*60+30, "CST", "CST", /* Aust: Central */
30 -8*60, "WST", 0, /* Aust: Western */
9d342dd9
BJ
31 -1
32};
33
34char *timezone(zone, dst)
35{
36 register struct zone *zp;
37 static char czone[10];
38 char *sign;
bdea7503
SL
39 register char *p, *q;
40 char *getenv(), *index();
9d342dd9 41
bdea7503
SL
42 if (p = getenv("TZNAME")) {
43 if (q = index(p, ',')) {
44 if (dst)
45 return(++q);
46 else {
47 *q = '\0';
48 strncpy(czone, p, sizeof(czone)-1);
49 czone[sizeof(czone)-1] = '\0';
50 *q = ',';
51 return (czone);
52 }
53 }
54 return(p);
55 }
9d342dd9
BJ
56 for (zp=zonetab; zp->offset!=-1; zp++)
57 if (zp->offset==zone) {
58 if (dst && zp->dlzone)
59 return(zp->dlzone);
60 if (!dst && zp->stdzone)
61 return(zp->stdzone);
62 }
63 if (zone<0) {
64 zone = -zone;
65 sign = "+";
66 } else
67 sign = "-";
68 sprintf(czone, "GMT%s%d:%02d", sign, zone/60, zone%60);
69 return(czone);
70}