Great idea! In fact, I had the same one earlier in this thread at least six hours ago. :-) Here's the relevant sub by itself:
use Inline C => q@
int epoch_sec(char * date) {
char *tz_str = date + 26;
struct tm tm;
int tz;
if ( strlen(date) != 31 ||
strptime(date, "%a, %d %b %Y %T", &tm) == NULL ||
sscanf(tz_str, "%d", &tz) != 1)
{
printf("Invalid date %s\n", date);
return 0;
}
return timegm(&tm) -
(tz < 0 ? -1 : 1)*(abs(tz)/100*3600 + abs(tz)%100*60);
}
@;
Performs about 25 times faster than str2time. |