11 /*********************************************************************
13 *********************************************************************/
15 static char *_DateDay[7]=
17 "Sun","Mon","Tue","Wed","Thu","Fri","Sat"
20 static char *_DateMonth[12]=
22 "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
25 static int32_t _DateTimeBias=0;
26 static char _DateTimeBiasStr[6]="";
28 abyss_bool DateToString(TDate *tm,char *s)
30 if (mktime(tm)==(time_t)(-1))
36 sprintf(s,"%s, %02d %s %04d %02d:%02d:%02d GMT",_DateDay[tm->tm_wday],tm->tm_mday,
37 _DateMonth[tm->tm_mon],tm->tm_year+1900,tm->tm_hour,tm->tm_min,tm->tm_sec);
45 DateToLogString(TDate * const tmP,
50 if (t != (time_t)(-1)) {
53 success = DateFromLocal(&d, t);
55 sprintf(s, "%02d/%s/%04d:%02d:%02d:%02d %s",
56 d.tm_mday, _DateMonth[d.tm_mon],
57 d.tm_year+1900, d.tm_hour, d.tm_min, d.tm_sec,
69 DateDecode(const char * const dateString,
78 /* Ignore spaces, day name and spaces */
79 while ((*s==' ') || (*s=='\t'))
82 while ((*s!=' ') && (*s!='\t'))
85 while ((*s==' ') || (*s=='\t'))
88 /* try to recognize the date format */
89 rc = sscanf(s, "%*s %d %d:%d:%d %d%*s", &tmP->tm_mday, &tmP->tm_hour,
90 &tmP->tm_min, &tmP->tm_sec, &tmP->tm_year);
93 rc = sscanf(s, "%d %n%*s %d %d:%d:%d GMT%*s",
94 &tmP->tm_mday,&n,&tmP->tm_year,
95 &tmP->tm_hour, &tmP->tm_min, &tmP->tm_sec);
98 rc = sscanf(s, "%d-%n%*[A-Za-z]-%d %d:%d:%d GMT%*s",
99 &tmP->tm_mday, &n, &tmP->tm_year,
100 &tmP->tm_hour, &tmP->tm_min, &tmP->tm_sec);
105 /* s points now to the month string */
107 for (n = 0; n < 12; ++n) {
112 if (tolower(*p++) == tolower(*s))
113 if (*p++ == tolower(s[1]))
114 if (*p == tolower(s[2]))
123 /* finish the work */
124 if (tmP->tm_year > 1900)
125 tmP->tm_year -= 1900;
127 if (tmP->tm_year < 70)
132 return (mktime(tmP) != (time_t)(-1));
137 int32_t DateCompare(TDate *d1,TDate *d2)
141 if ((x=d1->tm_year-d2->tm_year)==0)
142 if ((x=d1->tm_mon-d2->tm_mon)==0)
143 if ((x=d1->tm_mday-d2->tm_mday)==0)
144 if ((x=d1->tm_hour-d2->tm_hour)==0)
145 if ((x=d1->tm_min-d2->tm_min)==0)
146 x=d1->tm_sec-d2->tm_sec;
154 DateFromGMT(TDate *d,time_t t) {
166 abyss_bool DateFromLocal(TDate *d,time_t t)
168 return DateFromGMT(d,t+_DateTimeBias*2);
179 if (DateFromGMT(&gmt,t)) {
184 (local.tm_sec-gmt.tm_sec)+(local.tm_min-gmt.tm_min)*60
185 +(local.tm_hour-gmt.tm_hour)*3600;
186 sprintf(_DateTimeBiasStr, "%+03d%02d",
187 _DateTimeBias/3600,(abs(_DateTimeBias) % 3600)/60);