14887Schin /***********************************************************************
24887Schin * *
34887Schin * This software is part of the ast package *
4*12068SRoger.Faulkner@Oracle.COM * Copyright (c) 1985-2010 AT&T Intellectual Property *
54887Schin * and is licensed under the *
64887Schin * Common Public License, Version 1.0 *
78462SApril.Chin@Sun.COM * by AT&T Intellectual Property *
84887Schin * *
94887Schin * A copy of the License is available at *
104887Schin * http://www.opensource.org/licenses/cpl1.0.txt *
114887Schin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
124887Schin * *
134887Schin * Information and Software Systems Research *
144887Schin * AT&T Research *
154887Schin * Florham Park NJ *
164887Schin * *
174887Schin * Glenn Fowler <gsf@research.att.com> *
184887Schin * David Korn <dgk@research.att.com> *
194887Schin * Phong Vo <kpv@research.att.com> *
204887Schin * *
214887Schin ***********************************************************************/
224887Schin #pragma prototyped
234887Schin /*
244887Schin * Glenn Fowler
254887Schin * AT&T Research
264887Schin *
274887Schin * time conversion support
284887Schin */
294887Schin
304887Schin #include <ast.h>
314887Schin #include <tm.h>
324887Schin
334887Schin /*
344887Schin * return timezone pointer given name and type
354887Schin *
364887Schin * if type==0 then all time zone types match
374887Schin * otherwise type must be one of tm_info.zone[].type
384887Schin *
394887Schin * if end is non-null then it will point to the next
404887Schin * unmatched char in name
414887Schin *
424887Schin * if dst!=0 then it will point to 0 for standard zones
434887Schin * and the offset for daylight zones
444887Schin *
454887Schin * 0 returned for no match
464887Schin */
474887Schin
484887Schin Tm_zone_t*
tmzone(register const char * name,char ** end,const char * type,int * dst)494887Schin tmzone(register const char* name, char** end, const char* type, int* dst)
504887Schin {
514887Schin register Tm_zone_t* zp;
524887Schin register char* prev;
534887Schin char* e;
544887Schin
554887Schin static Tm_zone_t fixed;
564887Schin static char off[16];
574887Schin
584887Schin tmset(tm_info.zone);
594887Schin if ((*name == '+' || *name == '-') && (fixed.west = tmgoff(name, &e, TM_LOCALZONE)) != TM_LOCALZONE && !*e)
604887Schin {
614887Schin fixed.standard = fixed.daylight = strncpy(off, name, sizeof(off) - 1);
624887Schin if (end)
634887Schin *end = e;
644887Schin if (dst)
654887Schin *dst = 0;
664887Schin return &fixed;
674887Schin }
684887Schin zp = tm_info.local;
694887Schin prev = 0;
704887Schin do
714887Schin {
724887Schin if (zp->type)
734887Schin prev = zp->type;
744887Schin if (!type || type == prev || !prev)
754887Schin {
764887Schin if (tmword(name, end, zp->standard, NiL, 0))
774887Schin {
784887Schin if (dst)
794887Schin *dst = 0;
804887Schin return zp;
814887Schin }
824887Schin if (zp->dst && zp->daylight && tmword(name, end, zp->daylight, NiL, 0))
834887Schin {
844887Schin if (dst)
854887Schin *dst = zp->dst;
864887Schin return zp;
874887Schin }
884887Schin }
894887Schin if (zp == tm_info.local)
904887Schin zp = tm_data.zone;
914887Schin else
924887Schin zp++;
934887Schin } while (zp->standard);
944887Schin return 0;
954887Schin }
96