|
|
1.1 root 1: /*
2: * Copyright (c) 1987 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that: (1) source distributions retain this entire copyright
7: * notice and comment, and (2) distributions including binaries display
8: * the following acknowledgement: ``This product includes software
9: * developed by the University of California, Berkeley and its contributors''
10: * in the documentation or other materials provided with the distribution
11: * and in all advertising materials mentioning features or use of this
12: * software. Neither the name of the University nor the names of its
13: * contributors may be used to endorse or promote products derived
14: * from this software without specific prior written permission.
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18: */
19:
20: #if defined(LIBC_SCCS) && !defined(lint)
21: static char sccsid[] = "@(#)timezone.c 5.9 (Berkeley) 6/1/90";
22: #endif /* LIBC_SCCS and not lint */
23:
24: #include <sys/types.h>
25: #include <sys/time.h>
26: #include <stdio.h>
27: #include <tzfile.h>
28:
29: /*
30: * timezone --
31: * The arguments are the number of minutes of time you are westward
32: * from Greenwich and whether DST is in effect. It returns a string
33: * giving the name of the local timezone. Should be replaced, in the
34: * application code, by a call to localtime.
35: */
36:
37: static char czone[TZ_MAX_CHARS]; /* space for zone name */
38:
39: char *
40: timezone(zone, dst)
41: int zone,
42: dst;
43: {
44: register char *beg,
45: *end;
46: char *getenv(), *index(), *strncpy(), *_tztab();
47:
48: if (beg = getenv("TZNAME")) { /* set in environment */
49: if (end = index(beg, ',')) { /* "PST,PDT" */
50: if (dst)
51: return(++end);
52: *end = '\0';
53: (void)strncpy(czone,beg,sizeof(czone) - 1);
54: czone[sizeof(czone) - 1] = '\0';
55: *end = ',';
56: return(czone);
57: }
58: return(beg);
59: }
60: return(_tztab(zone,dst)); /* default: table or created zone */
61: }
62:
63: static struct zone {
64: int offset;
65: char *stdzone;
66: char *dlzone;
67: } zonetab[] = {
68: -1*60, "MET", "MET DST", /* Middle European */
69: -2*60, "EET", "EET DST", /* Eastern European */
70: 4*60, "AST", "ADT", /* Atlantic */
71: 5*60, "EST", "EDT", /* Eastern */
72: 6*60, "CST", "CDT", /* Central */
73: 7*60, "MST", "MDT", /* Mountain */
74: 8*60, "PST", "PDT", /* Pacific */
75: #ifdef notdef
76: /* there's no way to distinguish this from WET */
77: 0, "GMT", 0, /* Greenwich */
78: #endif
79: 0*60, "WET", "WET DST", /* Western European */
80: -10*60, "EST", "EST", /* Aust: Eastern */
81: -10*60+30, "CST", "CST", /* Aust: Central */
82: -8*60, "WST", 0, /* Aust: Western */
83: -1
84: };
85:
86: /*
87: * _tztab --
88: * check static tables or create a new zone name; broken out so that
89: * we can make a guess as to what the zone is if the standard tables
90: * aren't in place in /etc. DO NOT USE THIS ROUTINE OUTSIDE OF THE
91: * STANDARD LIBRARY.
92: */
93: char *
94: _tztab(zone,dst)
95: register int zone;
96: int dst;
97: {
98: register struct zone *zp;
99: register char sign;
100:
101: for (zp = zonetab; zp->offset != -1;++zp) /* static tables */
102: if (zp->offset == zone) {
103: if (dst && zp->dlzone)
104: return(zp->dlzone);
105: if (!dst && zp->stdzone)
106: return(zp->stdzone);
107: }
108:
109: if (zone < 0) { /* create one */
110: zone = -zone;
111: sign = '+';
112: }
113: else
114: sign = '-';
115: (void)sprintf(czone,"GMT%c%d:%02d",sign,zone / 60,zone % 60);
116: return(czone);
117: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.