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