d5d7871c9ce692f443b5a1f64194b4abe889f6b8 galt Mon Mar 7 22:21:10 2011 -0800 fixing processing of last-modified header in udc; also setting the original time on the finished file in paraFetch (net.c); new helper function in common.c handles conversion to UTC time diff --git src/lib/common.c src/lib/common.c index ca004a6..59481f5 100644 --- src/lib/common.c +++ src/lib/common.c @@ -2986,30 +2986,56 @@ return s; } char *splitOffNonNumeric(char *s) /* Split off non-numeric part, e.g. mm of mm8. Result should be freed when done */ { return cloneStringZ(s,skipToNumeric(s)-s); } char *splitOffNumber(char *db) /* Split off number part, e.g. 8 of mm8. Result should be freed when done */ { return cloneString(skipToNumeric(db)); } + +time_t mktimeFromUtc (struct tm *t) +/* Return time_t for tm in UTC (GMT) + * Useful for stuff like converting to time_t the + * last-modified HTTP response header + * which is always GMT. Returns -1 on failure of mktime */ +{ + time_t time; + char *tz; + char save_tz[100]; + tz=getenv("TZ"); + if (tz) + safecpy(save_tz, sizeof(save_tz), tz); + setenv("TZ", "GMT0", 1); + tzset(); + t->tm_isdst = 0; + time=mktime(t); + if (tz) + setenv("TZ", save_tz, 1); + else + unsetenv("TZ"); + tzset(); + return (time); +} + + time_t dateToSeconds(const char *date,const char*format) // Convert a string date to time_t { struct tm storage={0,0,0,0,0,0,0,0,0}; if(strptime(date,format,&storage)==NULL) return 0; else return mktime(&storage); } boolean dateIsOld(const char *date,const char*format) // Is this string date older than now? { time_t test = dateToSeconds(date,format); time_t now = clock1();