1/*********************************************************************** 2* * 3* This software is part of the ast package * 4* Copyright (c) 1985-2011 AT&T Intellectual Property * 5* and is licensed under the * 6* Eclipse Public License, Version 1.0 * 7* by AT&T Intellectual Property * 8* * 9* A copy of the License is available at * 10* http://www.eclipse.org/org/documents/epl-v10.html * 11* (with md5 checksum b35adb5213ca9657e911e9befb180842) * 12* * 13* Information and Software Systems Research * 14* AT&T Research * 15* Florham Park NJ * 16* * 17* Glenn Fowler <gsf@research.att.com> * 18* David Korn <dgk@research.att.com> * 19* Phong Vo <kpv@research.att.com> * 20* * 21***********************************************************************/ 22#pragma prototyped 23/* 24 * Glenn Fowler 25 * AT&T Research 26 * 27 * time conversion support 28 */ 29 30#include <ast.h> 31#include <tm.h> 32 33/* 34 * return timezone pointer given name and type 35 * 36 * if type==0 then all time zone types match 37 * otherwise type must be one of tm_info.zone[].type 38 * 39 * if end is non-null then it will point to the next 40 * unmatched char in name 41 * 42 * if dst!=0 then it will point to 0 for standard zones 43 * and the offset for daylight zones 44 * 45 * 0 returned for no match 46 */ 47 48Tm_zone_t* 49tmzone(register const char* name, char** end, const char* type, int* dst) 50{ 51 register Tm_zone_t* zp; 52 register char* prev; 53 char* e; 54 55 static Tm_zone_t fixed; 56 static char off[16]; 57 58 tmset(tm_info.zone); 59 if ((*name == '+' || *name == '-') && (fixed.west = tmgoff(name, &e, TM_LOCALZONE)) != TM_LOCALZONE && !*e) 60 { 61 strlcpy(fixed.standard = fixed.daylight = off, name, sizeof(off)); 62 if (end) 63 *end = e; 64 if (dst) 65 *dst = 0; 66 return &fixed; 67 } 68 zp = tm_info.local; 69 prev = 0; 70 do 71 { 72 if (zp->type) 73 prev = zp->type; 74 if (!type || type == prev || !prev) 75 { 76 if (tmword(name, end, zp->standard, NiL, 0)) 77 { 78 if (dst) 79 *dst = 0; 80 return zp; 81 } 82 if (zp->dst && zp->daylight && tmword(name, end, zp->daylight, NiL, 0)) 83 { 84 if (dst) 85 *dst = zp->dst; 86 return zp; 87 } 88 } 89 if (zp == tm_info.local) 90 zp = tm_data.zone; 91 else 92 zp++; 93 } while (zp->standard); 94 return 0; 95} 96