/* ** Localize a user profile by filling in all the information that we ** can figure out automatically, for example the email address, news ** server etc. */ PUBLIC BOOL HTUserProfile_localize (HTUserProfile * up) { if (up) { HTTRACE(CORE_TRACE, "User Profile Localizing %p\n" _ up); /* Find the FQDN */ up->fqdn = HTGetHostName(); /* Find the user email address */ up->email = HTGetMailAddress(); /* Find the news server */ up->news = HTGetNewsServer(); /* Find the timezone offset */ up->timezone = HTGetTimeZoneOffset(); /* Find the default location for temporary files */ StrAllocCopy(up->tmp, HT_TMP_ROOT); if (*(up->tmp+strlen(up->tmp)-1) != DIR_SEPARATOR_CHAR) StrAllocCat(up->tmp, DIR_SEPARATOR_STR); return YES; } return NO; }
int main (int argc, char ** argv) { time_t t = 0; HTLibInit("test","1.0"); t = HTGetTimeZoneOffset(); fprintf(stderr, "Timezone offset is %ld seconds or %ld hours\n", t, t/3600); HTLibTerminate(); return 0; }
/* ** Parse a str in GMT format to a local time time_t representation ** Four formats are accepted: ** ** Wkd, 00 Mon 0000 00:00:00 GMT (rfc1123) ** Weekday, 00-Mon-00 00:00:00 GMT (rfc850) ** Wkd Mon 00 00:00:00 0000 GMT (ctime) ** 1*DIGIT (delta-seconds) */ PUBLIC time_t HTParseTime (const char * str, HTUserProfile * up, BOOL expand) { char * s; struct tm tm; time_t t; if (!str) return 0; if ((s = strchr(str, ','))) { /* Thursday, 10-Jun-93 01:29:59 GMT */ s++; /* or: Thu, 10 Jan 1993 01:29:59 GMT */ while (*s && *s==' ') s++; if (strchr(s,'-')) { /* First format */ HTTRACE(CORE_TRACE, "Format...... Weekday, 00-Mon-00 00:00:00 GMT\n"); if ((int)strlen(s) < 18) { HTTRACE(CORE_TRACE, "ERROR....... Not a valid time format \"%s\"\n" _ s); return 0; } tm.tm_mday = strtol(s, &s, 10); tm.tm_mon = make_month(s, &s); tm.tm_year = strtol(++s, &s, 10); tm.tm_hour = strtol(s, &s, 10); tm.tm_min = strtol(++s, &s, 10); tm.tm_sec = strtol(++s, &s, 10); } else { /* Second format */ HTTRACE(CORE_TRACE, "Format...... Wkd, 00 Mon 0000 00:00:00 GMT\n"); if ((int)strlen(s) < 20) { HTTRACE(CORE_TRACE, "ERROR....... Not a valid time format \"%s\"\n" _ s); return 0; } tm.tm_mday = strtol(s, &s, 10); tm.tm_mon = make_month(s, &s); tm.tm_year = strtol(s, &s, 10) - 1900; tm.tm_hour = strtol(s, &s, 10); tm.tm_min = strtol(++s, &s, 10); tm.tm_sec = strtol(++s, &s, 10); } } else if (isdigit((int) *str)) { if (strchr(str, 'T')) { /* ISO (limited format) date string */ HTTRACE(CORE_TRACE, "Format...... YYYY.MM.DDThh:mmStzWkd\n"); s = (char *) str; while (*s && *s==' ') s++; if ((int)strlen(s) < 21) { HTTRACE(CORE_TRACE, "ERROR....... Not a valid time format `%s\'\n" _ s); return 0; } tm.tm_year = strtol(s, &s, 10) - 1900; tm.tm_mon = strtol(++s, &s, 10); tm.tm_mday = strtol(++s, &s, 10); tm.tm_hour = strtol(++s, &s, 10); tm.tm_min = strtol(++s, &s, 10); tm.tm_sec = strtol(++s, &s, 10); } else { /* delta seconds */ t = expand ? time(NULL) + atol(str) : atol(str); #ifdef HTDEBUG if (CORE_TRACE) { if (expand) { #if defined (HAVE_CTIME_R_2) char buffer[CTIME_MAX]; HTTRACE(CORE_TRACE, "Time string. Delta-time %s parsed to %ld seconds, or in local time: %s" _ str _ (long) t _ (char *) ctime_r(&t, buffer)); #elif defined(HAVE_CTIME_R_3) char buffer[CTIME_MAX]; HTTRACE(CORE_TRACE, "Time string. Delta-time %s parsed to %ld seconds, or in local time: %s" _ str _ (long) t _ (char *) ctime_r(&t, buffer, CTIME_MAX)); #else HTTRACE(CORE_TRACE, "Time string. Delta-time %s parsed to %ld seconds, or in local time: %s" _ str _ (long) t _ ctime(&t)); #endif /* HT_REENTRANT */ } else { HTTRACE(CORE_TRACE, "Time string. Delta-time %s parsed to %ld seconds\n" _ str _ (long) t); } } #endif /* HT_DEBUG */ return t; } } else { /* Try the other format: Wed Jun 9 01:29:59 1993 GMT */ HTTRACE(CORE_TRACE, "Format...... Wkd Mon 00 00:00:00 0000 GMT\n"); s = (char *) str; while (*s && *s==' ') s++; HTTRACE(CORE_TRACE, "Trying...... The Wrong time format: %s\n" _ s); if ((int)strlen(s) < 24) { HTTRACE(CORE_TRACE, "ERROR....... Not a valid time format \"%s\"\n" _ s); return 0; } tm.tm_mon = make_month(s, &s); tm.tm_mday = strtol(s, &s, 10); tm.tm_hour = strtol(s, &s, 10); tm.tm_min = strtol(++s, &s, 10); tm.tm_sec = strtol(++s, &s, 10); tm.tm_year = strtol(s, &s, 10) - 1900; } if (tm.tm_sec < 0 || tm.tm_sec > 59 || tm.tm_min < 0 || tm.tm_min > 59 || tm.tm_hour < 0 || tm.tm_hour > 23 || tm.tm_mday < 1 || tm.tm_mday > 31 || tm.tm_mon < 0 || tm.tm_mon > 11 || tm.tm_year <70 || tm.tm_year >120) { HTTRACE(CORE_TRACE, "ERROR....... Parsed illegal time: %02d.%02d.%02d %02d:%02d:%02d\n" _ tm.tm_mday _ tm.tm_mon+1 _ tm.tm_year _ tm.tm_hour _ tm.tm_min _ tm.tm_sec); return 0; } #if 0 #if defined(HAVE_TIMEZONE) && defined(HAVE_ALTZONE) tm.tm_isdst = daylight; /* Already taken into account */ HTTRACE(CORE_TRACE, "Time string. Daylight is %s\n" _ daylight>0 ? "on" : daylight==0 ? "off" : "unknown"); #endif #else /* Let mktime decide whether we have DST or not */ tm.tm_isdst = -1; #endif #ifdef HAVE_MKTIME t = mktime(&tm); t += (up ? HTUserProfile_timezone(up) : HTGetTimeZoneOffset()); #else #ifdef HAVE_TIMEGM t = timegm(&tm); #else #error "Neither mktime nor timegm defined" #endif /* HAVE_TIMEGM */ #endif /* HAVE_MKTIME */ HTTRACE(CORE_TRACE, "Time string. %s parsed to %ld calendar time or `%s' in local time\n" _ str _ (long) t _ ctime(&t)); return t; }