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