ezmlmx 0.68
ezmlmx
Loading...
Searching...
No Matches
date2yyyymm.c
Go to the documentation of this file.
1#include "date2yyyymm.h"
2
8
17
18unsigned int date2yyyymm(const char *s)
19{
20 unsigned int mo;
21 unsigned int year; /* must hold yyyymm - ok to year 65K */
22 char ch, ch1, ch2;
23
24/* jan feb mar apr may jun jul aug sep oct nov dec */
25/* - strictly qmail datefmt dependent*/
26 for (;;s++) {
27 ch = *s;
28 if (ch != ' ' && (ch < '0' || ch > '9')) break;
29 }
30 mo = 0;
31 if (!(ch = *(s++))) return 0;
32 if (ch >= 'a') ch -= ('a' - 'A'); /* toupper */
33 if (!(ch1 = *(s++))) return 0; /* rfc822 hrds are case-insens */
34 if (ch1 >= 'a') ch1 -= ('a' - 'A');
35 if (!(ch2 = *(s++))) return 0;
36 if (ch2 >= 'a') ch2 -= ('a' - 'A');
37
38 switch (ch) {
39 case 'J': if (ch1 == 'A' && ch2 == 'N') { mo = 1; break; }
40 if (ch1 == 'U') {
41 if (ch2 == 'N') mo = 6;
42 else if (ch2 == 'L') mo = 7;
43 }
44 break;
45 case 'F': if (ch1 == 'E' && ch2 == 'B') mo = 2; break;
46 case 'A': if (ch1 == 'P' && ch2 == 'R') mo = 4;
47 else if (ch1 == 'U' && ch2 == 'G') mo = 8;
48 break;
49 case 'M': if (ch1 != 'A') break;
50 if (ch2 == 'R') mo = 3;
51 else if (ch2 == 'Y') mo = 5;
52 break;
53 case 'S': if (ch1 == 'E' && ch2 == 'P') mo = 9; break;
54 case 'O': if (ch1 == 'C' && ch2 == 'T') mo = 10; break;
55 case 'N': if (ch1 == 'O' && ch2 == 'V') mo = 11; break;
56 case 'D': if (ch1 == 'E' && ch2 == 'C') mo = 12; break;
57 default: break;
58 }
59
60 if (!mo || *(s++) != ' ')
61 return 0L; /* mo true means s[0-2] valid */
62
63 year = 0L;
64 for (;;) {
65 unsigned char chy;
66 chy = (unsigned char) *(s++);
67 if (chy < '0' || chy > '9') {
68 if (year) break;
69 else return 0;
70 }
71 year = year * 10 + (chy - '0');
72 }
73
74 return year * 100 + mo;
75}
unsigned int date2yyyymm(const char *s)
Definition date2yyyymm.c:18