1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 1986 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*7c478bd9Sstevel@tonic-gate /* from UCB 4.4 83/09/25 */
29*7c478bd9Sstevel@tonic-gate
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate * The arguments are the number of minutes of time
32*7c478bd9Sstevel@tonic-gate * you are westward from Greenwich and whether DST is in effect.
33*7c478bd9Sstevel@tonic-gate * It returns a string
34*7c478bd9Sstevel@tonic-gate * giving the name of the local timezone.
35*7c478bd9Sstevel@tonic-gate *
36*7c478bd9Sstevel@tonic-gate * Sorry, I don't know all the names.
37*7c478bd9Sstevel@tonic-gate */
38*7c478bd9Sstevel@tonic-gate
39*7c478bd9Sstevel@tonic-gate static struct zone {
40*7c478bd9Sstevel@tonic-gate int offset;
41*7c478bd9Sstevel@tonic-gate char *stdzone;
42*7c478bd9Sstevel@tonic-gate char *dlzone;
43*7c478bd9Sstevel@tonic-gate } zonetab[] = {
44*7c478bd9Sstevel@tonic-gate -12*60, "NZST", "NZDT", /* New Zealand */
45*7c478bd9Sstevel@tonic-gate -10*60, "EST", "EST", /* Aust: Eastern */
46*7c478bd9Sstevel@tonic-gate -10*60+30, "CST", "CST", /* Aust: Central */
47*7c478bd9Sstevel@tonic-gate -8*60, "WST", 0, /* Aust: Western */
48*7c478bd9Sstevel@tonic-gate -9*60, "JST", 0, /* Japanese */
49*7c478bd9Sstevel@tonic-gate 0*60, "GMT", "BST", /* Great Britain and Eire */
50*7c478bd9Sstevel@tonic-gate -1*60, "MET", "MET DST", /* Middle European */
51*7c478bd9Sstevel@tonic-gate -2*60, "EET", "EET DST", /* Eastern European */
52*7c478bd9Sstevel@tonic-gate 3*60+30, "NST", "NDT", /* Newfoundland */
53*7c478bd9Sstevel@tonic-gate 4*60, "AST", "ADT", /* Atlantic */
54*7c478bd9Sstevel@tonic-gate 5*60, "EST", "EDT", /* Eastern */
55*7c478bd9Sstevel@tonic-gate 6*60, "CST", "CDT", /* Central */
56*7c478bd9Sstevel@tonic-gate 7*60, "MST", "MDT", /* Mountain */
57*7c478bd9Sstevel@tonic-gate 8*60, "PST", "PDT", /* Pacific */
58*7c478bd9Sstevel@tonic-gate 9*60, "YST", "YDT", /* Yukon */
59*7c478bd9Sstevel@tonic-gate 10*60, "HST", "HDT", /* Hawaiian */
60*7c478bd9Sstevel@tonic-gate -1
61*7c478bd9Sstevel@tonic-gate };
62*7c478bd9Sstevel@tonic-gate
timezone(zone,dst)63*7c478bd9Sstevel@tonic-gate char *timezone(zone, dst)
64*7c478bd9Sstevel@tonic-gate {
65*7c478bd9Sstevel@tonic-gate register struct zone *zp;
66*7c478bd9Sstevel@tonic-gate static char czone[10];
67*7c478bd9Sstevel@tonic-gate char *sign;
68*7c478bd9Sstevel@tonic-gate register char *p, *q;
69*7c478bd9Sstevel@tonic-gate char *getenv(), *index();
70*7c478bd9Sstevel@tonic-gate
71*7c478bd9Sstevel@tonic-gate if (p = getenv("TZNAME")) {
72*7c478bd9Sstevel@tonic-gate if (q = index(p, ',')) {
73*7c478bd9Sstevel@tonic-gate if (dst)
74*7c478bd9Sstevel@tonic-gate return(++q);
75*7c478bd9Sstevel@tonic-gate else {
76*7c478bd9Sstevel@tonic-gate *q = '\0';
77*7c478bd9Sstevel@tonic-gate strncpy(czone, p, sizeof(czone)-1);
78*7c478bd9Sstevel@tonic-gate czone[sizeof(czone)-1] = '\0';
79*7c478bd9Sstevel@tonic-gate *q = ',';
80*7c478bd9Sstevel@tonic-gate return (czone);
81*7c478bd9Sstevel@tonic-gate }
82*7c478bd9Sstevel@tonic-gate }
83*7c478bd9Sstevel@tonic-gate return(p);
84*7c478bd9Sstevel@tonic-gate }
85*7c478bd9Sstevel@tonic-gate for (zp=zonetab; zp->offset!=-1; zp++)
86*7c478bd9Sstevel@tonic-gate if (zp->offset==zone) {
87*7c478bd9Sstevel@tonic-gate if (dst && zp->dlzone)
88*7c478bd9Sstevel@tonic-gate return(zp->dlzone);
89*7c478bd9Sstevel@tonic-gate if (!dst && zp->stdzone)
90*7c478bd9Sstevel@tonic-gate return(zp->stdzone);
91*7c478bd9Sstevel@tonic-gate }
92*7c478bd9Sstevel@tonic-gate if (zone<0) {
93*7c478bd9Sstevel@tonic-gate zone = -zone;
94*7c478bd9Sstevel@tonic-gate sign = "+";
95*7c478bd9Sstevel@tonic-gate } else
96*7c478bd9Sstevel@tonic-gate sign = "-";
97*7c478bd9Sstevel@tonic-gate sprintf(czone, "GMT%s%d:%02d", sign, zone/60, zone%60);
98*7c478bd9Sstevel@tonic-gate return(czone);
99*7c478bd9Sstevel@tonic-gate }
100