1 # include	"../hdr/macros.h"
2 
3 SCCSID(@(#)date_ab.c	4.2);
4 
5 /*
6 	Function to convert date in the form "yymmddhhmmss" to
7 	standard UNIX time (seconds since Jan. 1, 1970 GMT).
8 	Units left off of the right are replaced by their
9 	maximum possible values.
10 
11 	The function corrects properly for leap year,
12 	daylight savings time, offset from Greenwich time, etc.
13 
14 	Function returns -1 if bad time is given (i.e., "730229").
15 */
16 char *Datep;
17 
18 
19 date_ab(adt,bdt)
20 char *adt;
21 long *bdt;
22 {
23 	int y, t, d, h, m, s, i;
24 	long tim;
25 	extern int *localtime();
26 #define	time_t	long
27 #include <sys/timeb.h>
28 	struct timeb timeb;
29 
30 	ftime(&timeb);
31 	Datep = adt;
32 
33 	if((y=g2()) == -2) y = 99;
34 	if(y<70 || y>99) return(-1);
35 
36 	if((t=g2()) == -2) t = 12;
37 	if(t<1 || t>12) return(-1);
38 
39 	if((d=g2()) == -2) d = mosize(y,t);
40 	if(d<1 || d>mosize(y,t)) return(-1);
41 
42 	if((h=g2()) == -2) h = 23;
43 	if(h<0 || h>23) return(-1);
44 
45 	if((m=g2()) == -2) m = 59;
46 	if(m<0 || m>59) return(-1);
47 
48 	if((s=g2()) == -2) s = 59;
49 	if(s<0 || s>59) return(-1);
50 
51 	tim = 0L;
52 	y =+ 1900;
53 	for(i=1970; i<y; i++)
54 		tim =+ dysize(i);
55 	while(--t)
56 		tim =+ mosize(y,t);
57 	tim =+ d - 1;
58 	tim =* 24;
59 	tim =+ h;
60 	tim =* 60;
61 	tim =+ m;
62 	tim =+ timeb.timezone;			/* GMT correction */
63 	tim =* 60;
64 	tim =+ s;
65 
66 	if(localtime(&tim)[8])
67 		tim =+ -1*60*60;		/* daylight savings */
68 	*bdt = tim;
69 	return(0);
70 }
71 
72 
73 mosize(y,t)
74 int y, t;
75 {
76 	extern int dmsize[];
77 
78 	if(t==2 && dysize(y)==366) return(29);
79 	return(dmsize[t-1]);
80 }
81 
82 
83 g2()
84 {
85 	register int c;
86 	register char *p;
87 
88 	for (p = Datep; *p; p++)
89 		if (numeric(*p))
90 			break;
91 	if (*p) {
92 		c = (*p++ - '0') * 10;
93 		if (*p)
94 			c =+ (*p++ - '0');
95 		else
96 			c = -1;
97 	}
98 	else
99 		c = -2;
100 	Datep = p;
101 	return(c);
102 }
103