54 else lval =
static_cast<long>(i);
65 long tmp = (lval>0 ? lval : -lval);
66 if (lval<0) *(t++) =
'-';
70 long y = tmp / 31536000L;
71 t += sprintf(t,
"%liY", y);
76 long d = tmp / 86400L;
77 t += sprintf(t,
"%liD", d);
86 t += sprintf(t,
"%liH", h);
92 t += sprintf(t,
"%liM", h);
96 sprintf(t,
"%liS", tmp);
105 char *pos = r + start.toCharBuffer(r);
108 strcat(pos, separator.c_str());
109 pos += separatorlength;
112 end.toCharBuffer(pos);
121 bool negative =
false;
133 throw DataException(
"Invalid time string '" +
string(s) +
"'");
137 for ( ; *c && *c !=
'T'; ++c)
141 case '0':
case '1':
case '2':
case '3':
case '4':
142 case '5':
case '6':
case '7':
case '8':
case '9':
143 value = value * 10 + (*c -
'0');
146 totalvalue += value * 31536000L;
151 totalvalue += value * 2628000L;
155 totalvalue += value * 604800L;
159 totalvalue += value * 86400L;
163 throw DataException(
"Invalid time string '" +
string(s) +
"'");
174 case '0':
case '1':
case '2':
case '3':
case '4':
175 case '5':
case '6':
case '7':
case '8':
case '9':
176 value = value * 10 + (*c -
'0');
179 totalvalue += value * 3600L;
183 totalvalue += value * 60L;
191 throw DataException(
"Invalid time string '" +
string(s) +
"'");
197 if (value)
throw DataException(
"Invalid time string '" +
string(s) +
"'");
200 lval = negative ? -totalvalue : totalvalue;
213 strptime(s, fmt.c_str(), &p);
221 (
int year,
int month,
int day,
int hr,
int min,
int sec)
225 p.tm_year = year - 1900;
226 p.tm_mon = month - 1;
238 #ifndef HAVE_STRPTIME
240 DECLARE_EXPORT char* Date::strptime(
const char *buf,
const char *fmt,
struct tm *tm)
244 char *abbrev_month_names[12];
245 size_t len_abbrev_month_names[12];
246 char *month_names[12];
247 size_t len_month_names[12];
248 char *abbrev_weekday_names[7];
249 size_t len_abbrev_weekday_names[7];
250 char *weekday_names[7];
251 size_t len_weekday_names[7];
256 size_t len_am_string;
258 size_t len_pm_string;
260 unsigned short numWeekdays;
261 unsigned short numMonths;
265 static struct dtconv En_US =
268 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
269 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
276 "January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
277 "September",
"October",
"November",
"December"
280 8, 8, 5, 5, 3, 4, 4, 6,
283 {
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat" },
284 { 3, 3, 3, 3, 3, 3, 3},
286 "Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
315 if (*buf == 0)
break;
320 while (*buf != 0 && isspace(*buf)) buf++;
321 else if (c != *buf++)
return 0;
330 if (*buf++ !=
'%')
return 0;
334 buf = strptime(buf, En_US.lDate_format, tm);
335 if (buf == 0)
return 0;
339 buf = strptime(buf,
"%x %X", tm);
340 if (buf == 0)
return 0;
344 buf = strptime(buf,
"%m/%d/%y", tm);
345 if (buf == 0)
return 0;
349 buf = strptime(buf,
"%H:%M", tm);
350 if (buf == 0)
return 0;
354 buf = strptime(buf,
"%I:%M:%S %p", tm);
355 if (buf == 0)
return 0;
359 buf = strptime(buf,
"%H:%M:%S", tm);
360 if (buf == 0)
return 0;
364 buf = strptime(buf, En_US.time_format, tm);
365 if (buf == 0)
return 0;
369 buf = strptime(buf, En_US.sDate_format, tm);
370 if (buf == 0)
return 0;
374 if (!isdigit(*buf))
return 0;
375 for (i = 0; *buf != 0 && isdigit(*buf); ++buf)
380 if (i > 365)
return 0;
386 if (*buf == 0 || isspace(*buf))
break;
387 if (!isdigit(*buf))
return 0;
388 for (i = 0; *buf != 0 && isdigit(*buf); ++buf)
393 if (i > 59)
return 0;
398 if (*buf != 0 && isspace(*buf))
399 while (*ptr != 0 && !isspace(*ptr)) ++ptr;
406 if (!isdigit(*buf))
return 0;
407 for (i = 0; *buf != 0 && isdigit(*buf); ++buf)
412 if (c ==
'H' || c ==
'k')
413 {
if (i > 23)
return 0;}
414 else if (i > 11)
return 0;
416 if (*buf != 0 && isspace(*buf))
417 while (*ptr != 0 && !isspace(*ptr)) ++ptr;
421 if (strncasecmp(buf, En_US.am_string, En_US.len_am_string) == 0)
423 if (tm->tm_hour > 12)
return 0;
424 if (tm->tm_hour == 12) tm->tm_hour = 0;
428 if (strncasecmp(buf, En_US.pm_string, En_US.len_pm_string) == 0)
430 if (tm->tm_hour > 12)
return 0;
431 if (tm->tm_hour != 12) tm->tm_hour += 12;
439 for (i = 0; i < En_US.numWeekdays; ++i)
441 if (strncasecmp(buf, En_US.weekday_names[i],
442 En_US.len_weekday_names[i]) == 0)
break;
443 if (strncasecmp(buf, En_US.abbrev_weekday_names[i],
444 En_US.len_abbrev_weekday_names[i]) == 0)
break;
446 if (i == En_US.numWeekdays)
return 0;
453 if (!isdigit(*buf))
return 0;
454 for (i = 0; *buf != 0 && isdigit(*buf); ++buf)
459 if (i > 31)
return 0;
461 if (*buf != 0 && isspace(*buf))
462 while (*ptr != 0 && !isspace(*ptr)) ++ptr;
468 for (i = 0; i < En_US.numMonths; ++i)
470 if (strncasecmp(buf, En_US.month_names[i],
471 En_US.len_month_names[i]) == 0)
break;
472 if (strncasecmp(buf, En_US.abbrev_month_names[i],
473 En_US.len_abbrev_month_names[i]) == 0)
break;
475 if (i == En_US.numMonths)
return 0;
481 if (!isdigit(*buf))
return 0;
482 for (i = 0; *buf != 0 && isdigit(*buf); ++buf)
487 if (i < 1 || i > 12)
return 0;
489 if (*buf != 0 && isspace(*buf))
490 while (*ptr != 0 && !isspace(*ptr)) ++ptr;
495 if (*buf == 0 || isspace(*buf))
break;
496 if (!isdigit(*buf))
return 0;
497 for (i = 0; *buf != 0 && isdigit(*buf); ++buf)
502 if (c ==
'Y') i -= 1900;
505 if (*buf != 0 && isspace(*buf))
506 while (*ptr != 0 && !isspace(*ptr)) ++ptr;
511 return const_cast<char*
>(buf);