Commit | Line | Data |
---|---|---|
bb0cfa24 | 1 | /* |
5d10bbb4 | 2 | * Copyright (c) 1987 Regents of the University of California. |
063836de KB |
3 | * All rights reserved. |
4 | * | |
269a7923 | 5 | * %sccs.include.redist.c% |
bb0cfa24 DF |
6 | */ |
7 | ||
03f05ee5 | 8 | #if defined(LIBC_SCCS) && !defined(lint) |
269a7923 | 9 | static char sccsid[] = "@(#)timezone.c 5.9 (Berkeley) %G%"; |
063836de | 10 | #endif /* LIBC_SCCS and not lint */ |
5d10bbb4 KB |
11 | |
12 | #include <sys/types.h> | |
13 | #include <sys/time.h> | |
14 | #include <stdio.h> | |
15 | #include <tzfile.h> | |
bb0cfa24 | 16 | |
9d342dd9 | 17 | /* |
5d10bbb4 KB |
18 | * timezone -- |
19 | * The arguments are the number of minutes of time you are westward | |
20 | * from Greenwich and whether DST is in effect. It returns a string | |
21 | * giving the name of the local timezone. Should be replaced, in the | |
22 | * application code, by a call to localtime. | |
9d342dd9 BJ |
23 | */ |
24 | ||
5d10bbb4 KB |
25 | static char czone[TZ_MAX_CHARS]; /* space for zone name */ |
26 | ||
27 | char * | |
28 | timezone(zone, dst) | |
29 | int zone, | |
30 | dst; | |
31 | { | |
32 | register char *beg, | |
33 | *end; | |
db546bc5 | 34 | char *getenv(), *index(), *strncpy(), *_tztab(); |
5d10bbb4 KB |
35 | |
36 | if (beg = getenv("TZNAME")) { /* set in environment */ | |
37 | if (end = index(beg, ',')) { /* "PST,PDT" */ | |
38 | if (dst) | |
39 | return(++end); | |
40 | *end = '\0'; | |
41 | (void)strncpy(czone,beg,sizeof(czone) - 1); | |
42 | czone[sizeof(czone) - 1] = '\0'; | |
43 | *end = ','; | |
44 | return(czone); | |
45 | } | |
46 | return(beg); | |
47 | } | |
db546bc5 | 48 | return(_tztab(zone,dst)); /* default: table or created zone */ |
5d10bbb4 KB |
49 | } |
50 | ||
9d342dd9 BJ |
51 | static struct zone { |
52 | int offset; | |
53 | char *stdzone; | |
54 | char *dlzone; | |
55 | } zonetab[] = { | |
5d10bbb4 KB |
56 | -1*60, "MET", "MET DST", /* Middle European */ |
57 | -2*60, "EET", "EET DST", /* Eastern European */ | |
58 | 4*60, "AST", "ADT", /* Atlantic */ | |
59 | 5*60, "EST", "EDT", /* Eastern */ | |
60 | 6*60, "CST", "CDT", /* Central */ | |
61 | 7*60, "MST", "MDT", /* Mountain */ | |
62 | 8*60, "PST", "PDT", /* Pacific */ | |
7f253f66 SL |
63 | #ifdef notdef |
64 | /* there's no way to distinguish this from WET */ | |
5d10bbb4 | 65 | 0, "GMT", 0, /* Greenwich */ |
7f253f66 | 66 | #endif |
5d10bbb4 KB |
67 | 0*60, "WET", "WET DST", /* Western European */ |
68 | -10*60, "EST", "EST", /* Aust: Eastern */ | |
69 | -10*60+30, "CST", "CST", /* Aust: Central */ | |
70 | -8*60, "WST", 0, /* Aust: Western */ | |
9d342dd9 BJ |
71 | -1 |
72 | }; | |
73 | ||
5d10bbb4 | 74 | /* |
db546bc5 | 75 | * _tztab -- |
5d10bbb4 KB |
76 | * check static tables or create a new zone name; broken out so that |
77 | * we can make a guess as to what the zone is if the standard tables | |
78 | * aren't in place in /etc. DO NOT USE THIS ROUTINE OUTSIDE OF THE | |
79 | * STANDARD LIBRARY. | |
80 | */ | |
81 | char * | |
2555d7f3 | 82 | _tztab(zone,dst) |
5d10bbb4 KB |
83 | register int zone; |
84 | int dst; | |
9d342dd9 | 85 | { |
5d10bbb4 KB |
86 | register struct zone *zp; |
87 | register char sign; | |
9d342dd9 | 88 | |
5d10bbb4 KB |
89 | for (zp = zonetab; zp->offset != -1;++zp) /* static tables */ |
90 | if (zp->offset == zone) { | |
9d342dd9 BJ |
91 | if (dst && zp->dlzone) |
92 | return(zp->dlzone); | |
93 | if (!dst && zp->stdzone) | |
94 | return(zp->stdzone); | |
95 | } | |
5d10bbb4 KB |
96 | |
97 | if (zone < 0) { /* create one */ | |
9d342dd9 | 98 | zone = -zone; |
5d10bbb4 KB |
99 | sign = '+'; |
100 | } | |
101 | else | |
102 | sign = '-'; | |
103 | (void)sprintf(czone,"GMT%c%d:%02d",sign,zone / 60,zone % 60); | |
9d342dd9 BJ |
104 | return(czone); |
105 | } |