11993Swnj /* 2*21365Sdist * Copyright (c) 1980 Regents of the University of California. 3*21365Sdist * All rights reserved. The Berkeley software License Agreement 4*21365Sdist * specifies the terms and conditions for redistribution. 5*21365Sdist */ 6*21365Sdist 7*21365Sdist #ifndef lint 8*21365Sdist static char sccsid[] = "@(#)timezone.c 5.1 (Berkeley) 05/30/85"; 9*21365Sdist #endif not lint 10*21365Sdist 11*21365Sdist /* 121993Swnj * The arguments are the number of minutes of time 131993Swnj * you are westward from Greenwich and whether DST is in effect. 141993Swnj * It returns a string 151993Swnj * giving the name of the local timezone. 161993Swnj * 171993Swnj * Sorry, I don't know all the names. 181993Swnj */ 191993Swnj 201993Swnj static struct zone { 211993Swnj int offset; 221993Swnj char *stdzone; 231993Swnj char *dlzone; 241993Swnj } zonetab[] = { 2515096Skarels -1*60, "MET", "MET DST", /* Middle European */ 2615096Skarels -2*60, "EET", "EET DST", /* Eastern European */ 271993Swnj 4*60, "AST", "ADT", /* Atlantic */ 281993Swnj 5*60, "EST", "EDT", /* Eastern */ 291993Swnj 6*60, "CST", "CDT", /* Central */ 301993Swnj 7*60, "MST", "MDT", /* Mountain */ 311993Swnj 8*60, "PST", "PDT", /* Pacific */ 3213877Ssam #ifdef notdef 3313877Ssam /* there's no way to distinguish this from WET */ 341993Swnj 0, "GMT", 0, /* Greenwich */ 3513877Ssam #endif 3613877Ssam 0*60, "WET", "WET DST", /* Western European */ 3712974Ssam -10*60, "EST", "EST", /* Aust: Eastern */ 3812974Ssam -10*60+30, "CST", "CST", /* Aust: Central */ 3912974Ssam -8*60, "WST", 0, /* Aust: Western */ 401993Swnj -1 411993Swnj }; 421993Swnj 431993Swnj char *timezone(zone, dst) 441993Swnj { 451993Swnj register struct zone *zp; 461993Swnj static char czone[10]; 471993Swnj char *sign; 4812974Ssam register char *p, *q; 4912974Ssam char *getenv(), *index(); 501993Swnj 5112974Ssam if (p = getenv("TZNAME")) { 5212974Ssam if (q = index(p, ',')) { 5312974Ssam if (dst) 5412974Ssam return(++q); 5512974Ssam else { 5612974Ssam *q = '\0'; 5712974Ssam strncpy(czone, p, sizeof(czone)-1); 5812974Ssam czone[sizeof(czone)-1] = '\0'; 5912974Ssam *q = ','; 6012974Ssam return (czone); 6112974Ssam } 6212974Ssam } 6312974Ssam return(p); 6412974Ssam } 651993Swnj for (zp=zonetab; zp->offset!=-1; zp++) 661993Swnj if (zp->offset==zone) { 671993Swnj if (dst && zp->dlzone) 681993Swnj return(zp->dlzone); 691993Swnj if (!dst && zp->stdzone) 701993Swnj return(zp->stdzone); 711993Swnj } 721993Swnj if (zone<0) { 731993Swnj zone = -zone; 741993Swnj sign = "+"; 751993Swnj } else 761993Swnj sign = "-"; 771993Swnj sprintf(czone, "GMT%s%d:%02d", sign, zone/60, zone%60); 781993Swnj return(czone); 791993Swnj } 80