Mercurial > hg
changeset 802:dd860da62002
Enable use on systems that do not have tm_gmtoff including Cygwin
author | Soren Andersen <somian@pobox.com> |
---|---|
date | Mon, 10 Apr 2006 23:25:32 +0200 |
parents | d8e0a1ce3e8a |
children | 8f8d8f8157a2 |
files | mcabber/src/utils.c |
diffstat | 1 files changed, 29 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/mcabber/src/utils.c Mon Apr 10 23:21:47 2006 +0200 +++ b/mcabber/src/utils.c Mon Apr 10 23:25:32 2006 +0200 @@ -25,6 +25,12 @@ #include <stdlib.h> #include <string.h> #include <stdarg.h> + +/* For Cygwin (thanks go to Yitzchak Scott-Thoennes) */ +#ifdef __CYGWIN__ +# define timezonevar + extern long timezone; +#endif #include <time.h> #include <unistd.h> #include <sys/types.h> @@ -187,9 +193,10 @@ } // from_iso8601(timestamp, utc) -// This function comes from the Gaim project, gaim_str_to_time(). +// This function came from the Gaim project, gaim_str_to_time(). // (Actually date may not be pure iso-8601) // Thanks, guys! +// ** Modified by somian 10 Apr 2006 with advice from ysth. time_t from_iso8601(const char *timestamp, int utc) { struct tm t; @@ -197,6 +204,7 @@ char buf[32]; char *c; int tzoff = 0; + int hms_succ = 0; time(&retval); localtime_r(&retval, &t); @@ -230,10 +238,20 @@ c++; /* skip the "T" */ /* 2 digit hour */ - if (sscanf(c, "%02d:%02d:%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3 || - sscanf(c, "%02d%02d%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3) { + if (sscanf(c, "%02d:%02d:%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3) + { + hms_succ = 1; + c += 8; + } + else if (sscanf(c, "%02d%02d%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3) + { + hms_succ = 1; + c += 6; + } + + if (hms_succ) { int tzhrs, tzmins; - c+=8; + if (*c == '.') /* dealing with precision we don't care about */ c += 4; @@ -245,15 +263,14 @@ } if (tzoff || utc) { - -//#ifdef HAVE_TM_GMTOFF +#ifdef HAVE_TM_GMTOFF tzoff += t.tm_gmtoff; -//#else -//# ifdef HAVE_TIMEZONE -// tzset(); /* making sure */ -// tzoff -= timezone; -//# endif -//#endif +#else +# ifdef HAVE_TIMEZONE + tzset(); /* making sure */ + tzoff -= timezone; +# endif +#endif } } }