Annotation of 43BSD/lib/libc/gen/timezone.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1980 Regents of the University of California.
                      3:  * All rights reserved.  The Berkeley software License Agreement
                      4:  * specifies the terms and conditions for redistribution.
                      5:  */
                      6: 
                      7: #if defined(LIBC_SCCS) && !defined(lint)
                      8: static char sccsid[] = "@(#)timezone.c 5.2 (Berkeley) 3/9/86";
                      9: #endif LIBC_SCCS and not lint
                     10: 
                     11: /*
                     12:  * The arguments are the number of minutes of time
                     13:  * you are westward from Greenwich and whether DST is in effect.
                     14:  * It returns a string
                     15:  * giving the name of the local timezone.
                     16:  *
                     17:  * Sorry, I don't know all the names.
                     18:  */
                     19: 
                     20: static struct zone {
                     21:        int     offset;
                     22:        char    *stdzone;
                     23:        char    *dlzone;
                     24: } zonetab[] = {
                     25:        -1*60, "MET", "MET DST",        /* Middle European */
                     26:        -2*60, "EET", "EET DST",        /* Eastern European */
                     27:        4*60, "AST", "ADT",             /* Atlantic */
                     28:        5*60, "EST", "EDT",             /* Eastern */
                     29:        6*60, "CST", "CDT",             /* Central */
                     30:        7*60, "MST", "MDT",             /* Mountain */
                     31:        8*60, "PST", "PDT",             /* Pacific */
                     32: #ifdef notdef
                     33:        /* there's no way to distinguish this from WET */
                     34:        0, "GMT", 0,                    /* Greenwich */
                     35: #endif
                     36:        0*60, "WET", "WET DST",         /* Western European */
                     37:        -10*60, "EST", "EST",           /* Aust: Eastern */
                     38:        -10*60+30, "CST", "CST",        /* Aust: Central */
                     39:        -8*60, "WST", 0,                /* Aust: Western */
                     40:        -1
                     41: };
                     42: 
                     43: char *timezone(zone, dst)
                     44: {
                     45:        register struct zone *zp;
                     46:        static char czone[10];
                     47:        char *sign;
                     48:        register char *p, *q;
                     49:        char *getenv(), *index();
                     50: 
                     51:        if (p = getenv("TZNAME")) {
                     52:                if (q = index(p, ',')) {
                     53:                        if (dst)
                     54:                                return(++q);
                     55:                        else {
                     56:                                *q = '\0';
                     57:                                strncpy(czone, p, sizeof(czone)-1);
                     58:                                czone[sizeof(czone)-1] = '\0';
                     59:                                *q = ',';
                     60:                                return (czone);
                     61:                        }
                     62:                }
                     63:                return(p);
                     64:        }
                     65:        for (zp=zonetab; zp->offset!=-1; zp++)
                     66:                if (zp->offset==zone) {
                     67:                        if (dst && zp->dlzone)
                     68:                                return(zp->dlzone);
                     69:                        if (!dst && zp->stdzone)
                     70:                                return(zp->stdzone);
                     71:                }
                     72:        if (zone<0) {
                     73:                zone = -zone;
                     74:                sign = "+";
                     75:        } else
                     76:                sign = "-";
                     77:        sprintf(czone, "GMT%s%d:%02d", sign, zone/60, zone%60);
                     78:        return(czone);
                     79: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.