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