char dtcvt__[] "~|^`dtcvt.c:	2.3";
/*
	Function to convert date in the form "yymmddhhmmss" to
	standard UNIX time (seconds since Jan. 1, 1970 GMT).
	Units left off of the right are replaced by their
	maximum possible values.

	The function corrects properly for leap year,
	daylight savings time, offset from Greenwich time, etc.

	Function returns -1 if bad time is given (i.e., "730229").
*/
char *cbp;
int timbuf[2];


dtcvt(adt,bdt)
char *adt;
int bdt[];
{
	int y, t, d, h, m, s, i;
	extern int timezone, *localtime();

	cbp = adt;

	if((y=g2()) == -2) y = 99;
	if(y<70 || y>99) return(-1);

	if((t=g2()) == -2) t = 12;
	if(t<1 || t>12) return(-1);

	if((d=g2()) == -2) d = mosize(y,t);
	if(d<1 || d>mosize(y,t)) return(-1);

	if((h=g2()) == -2) h = 23;
	if(h<0 || h>23) return(-1);

	if((m=g2()) == -2) m = 59;
	if(m<0 || m>59) return(-1);

	if((s=g2()) == -2) s = 59;
	if(s<0 || s>59) return(-1);

	timbuf[0] = timbuf[1] = 0;
	y =+ 1900;
	for(i=1970; i<y; i++) gdadd(dysize(i));
	while(--t) gdadd(mosize(y,t));
	gdadd(d-1);
	gmdadd(24,h);
	gmdadd(60,m);
	gmdadd(60,s);

	dpadd(timbuf,timezone);			/* GMT correction */
	if(localtime(timbuf)[8])
		dpadd(timbuf,-1*60*60);		/* daylight savings */
	bdt[0] = timbuf[0];
	bdt[1] = timbuf[1];
	return(0);
}


mosize(y,t)
int y, t;
{
	extern int dmsize[];

	if(t==2 && dysize(y)==366) return(29);
	return(dmsize[t-1]);
}


g2()
{
	register int c;

	if(*cbp == '\0') return(-2);
	c = (*cbp++ - '0') * 10;
	if(*cbp == '\0') return(-1);
	return(*cbp++ - '0' + c);
}


gdadd(n)
{
	register char *t;

	t = timbuf[1]+n;
	if(t < timbuf[1])
		timbuf[0]++;
	timbuf[1] = t;
}

gmdadd(m, n)
{
	register int t1;

	timbuf[0] =* m;
	t1 = timbuf[1];
	while(--m)
		gdadd(t1);
	gdadd(n);
}
