12168Seric # include	"../hdr/macros.h"
22168Seric 
3*19936Ssam SCCSID(@(#)date_ab.c	4.3);
42168Seric 
52168Seric /*
62168Seric 	Function to convert date in the form "yymmddhhmmss" to
72168Seric 	standard UNIX time (seconds since Jan. 1, 1970 GMT).
82168Seric 	Units left off of the right are replaced by their
92168Seric 	maximum possible values.
102168Seric 
112168Seric 	The function corrects properly for leap year,
122168Seric 	daylight savings time, offset from Greenwich time, etc.
132168Seric 
142168Seric 	Function returns -1 if bad time is given (i.e., "730229").
152168Seric */
162168Seric char *Datep;
172168Seric 
182168Seric 
192168Seric date_ab(adt,bdt)
202168Seric char *adt;
212168Seric long *bdt;
222168Seric {
232168Seric 	int y, t, d, h, m, s, i;
242168Seric 	long tim;
252168Seric 	extern int *localtime();
262168Seric #define	time_t	long
272168Seric #include <sys/timeb.h>
282168Seric 	struct timeb timeb;
292168Seric 
302168Seric 	ftime(&timeb);
312168Seric 	Datep = adt;
322168Seric 
332168Seric 	if((y=g2()) == -2) y = 99;
342168Seric 	if(y<70 || y>99) return(-1);
352168Seric 
362168Seric 	if((t=g2()) == -2) t = 12;
372168Seric 	if(t<1 || t>12) return(-1);
382168Seric 
392168Seric 	if((d=g2()) == -2) d = mosize(y,t);
402168Seric 	if(d<1 || d>mosize(y,t)) return(-1);
412168Seric 
422168Seric 	if((h=g2()) == -2) h = 23;
432168Seric 	if(h<0 || h>23) return(-1);
442168Seric 
452168Seric 	if((m=g2()) == -2) m = 59;
462168Seric 	if(m<0 || m>59) return(-1);
472168Seric 
482168Seric 	if((s=g2()) == -2) s = 59;
492168Seric 	if(s<0 || s>59) return(-1);
502168Seric 
512168Seric 	tim = 0L;
522168Seric 	y =+ 1900;
532168Seric 	for(i=1970; i<y; i++)
542168Seric 		tim =+ dysize(i);
552168Seric 	while(--t)
562168Seric 		tim =+ mosize(y,t);
572168Seric 	tim =+ d - 1;
582168Seric 	tim =* 24;
592168Seric 	tim =+ h;
602168Seric 	tim =* 60;
612168Seric 	tim =+ m;
622294Seric 	tim =+ timeb.timezone;			/* GMT correction */
632168Seric 	tim =* 60;
642168Seric 	tim =+ s;
652168Seric 
662168Seric 	if(localtime(&tim)[8])
672168Seric 		tim =+ -1*60*60;		/* daylight savings */
682168Seric 	*bdt = tim;
692168Seric 	return(0);
702168Seric }
712168Seric 
722168Seric 
732168Seric mosize(y,t)
742168Seric int y, t;
752168Seric {
76*19936Ssam 	static	int dmsize[12] =
77*19936Ssam 	    { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
782168Seric 
792168Seric 	if(t==2 && dysize(y)==366) return(29);
802168Seric 	return(dmsize[t-1]);
812168Seric }
822168Seric 
832168Seric 
842168Seric g2()
852168Seric {
862168Seric 	register int c;
872168Seric 	register char *p;
882168Seric 
892168Seric 	for (p = Datep; *p; p++)
902168Seric 		if (numeric(*p))
912168Seric 			break;
922168Seric 	if (*p) {
932168Seric 		c = (*p++ - '0') * 10;
942168Seric 		if (*p)
952168Seric 			c =+ (*p++ - '0');
962168Seric 		else
972168Seric 			c = -1;
982168Seric 	}
992168Seric 	else
1002168Seric 		c = -2;
1012168Seric 	Datep = p;
1022168Seric 	return(c);
1032168Seric }
104