Changeset: 98f67ae9b5e2 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/98f67ae9b5e2 Modified Files: clients/mapilib/mapi.c cmake/monetdb-defines.cmake monetdb5/modules/atoms/mtime.c monetdb_config.h.in Branch: default Log Message:
Use tm_gmtoff field in struct tm if we have it, or use Windows-specific code. diffs (79 lines): diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c --- a/clients/mapilib/mapi.c +++ b/clients/mapilib/mapi.c @@ -1934,14 +1934,40 @@ mapi_new(void) mid->blk.buf[mid->blk.lim] = 0; /* also the current timezone, seconds EAST of UTC */ +#if defined(_MSC_VER) + DYNAMIC_TIME_ZONE_INFORMATION tzinf; + + /* documentation says: UTC = localtime + Bias (in minutes), + * but experimentation during DST period says, UTC = localtime + * + Bias + DaylightBias, and presumably during non DST + * period, UTC = localtime + Bias */ + switch (GetDynamicTimeZoneInformation(&tzinf)) { + case TIME_ZONE_ID_STANDARD: /* using standard time */ + case TIME_ZONE_ID_UNKNOWN: /* no daylight saving time in this zone */ + mid->time_zone = -(int) tzinf.Bias * 60; + break; + case TIME_ZONE_ID_DAYLIGHT: /* using daylight saving time */ + mid->time_zone = -(int) (tzinf.Bias + tzinf.DaylightBias) * 60; + break; + default: /* aka TIME_ZONE_ID_INVALID */ + /* call failed, we don't know the time zone */ + mid->time_zone = 0; + break; + } +#else time_t t = time(NULL); + struct tm *local_tm = localtime_r(&t, &(struct tm){0}); +#ifdef HAVE_TM_GMTOFF + mid->time_zone = (int) local_tm->tm_gmtoff; +#else struct tm *gm_tm = gmtime_r(&t, &(struct tm){0}); time_t gt = mktime(gm_tm); - struct tm *local_tm = localtime_r(&t, &(struct tm){0}); local_tm->tm_isdst=0; /* We need the difference without dst */ time_t lt = mktime(local_tm); assert((int64_t) gt - (int64_t) lt >= (int64_t) INT_MIN && (int64_t) gt - (int64_t) lt <= (int64_t) INT_MAX); mid->time_zone = (int) (lt - gt); +#endif +#endif return mid; } diff --git a/cmake/monetdb-defines.cmake b/cmake/monetdb-defines.cmake --- a/cmake/monetdb-defines.cmake +++ b/cmake/monetdb-defines.cmake @@ -67,6 +67,7 @@ function(monetdb_configure_defines) check_symbol_exists("asctime_r" "time.h" HAVE_ASCTIME_R) check_symbol_exists("clock_gettime" "time.h" HAVE_CLOCK_GETTIME) check_symbol_exists("ctime_r" "time.h" HAVE_CTIME_R) + check_struct_has_member("struct tm" tm_gmtoff time.h HAVE_TM_GMTOFF) check_symbol_exists("dispatch_semaphore_create" "dispatch/dispatch.h" HAVE_DISPATCH_SEMAPHORE_CREATE) # Linux specific, in the future, it might be ported to other platforms diff --git a/monetdb5/modules/atoms/mtime.c b/monetdb5/modules/atoms/mtime.c --- a/monetdb5/modules/atoms/mtime.c +++ b/monetdb5/modules/atoms/mtime.c @@ -779,7 +779,7 @@ local_timezone(int *isdstp) tzone = 0; break; } -#elif defined(HAVE_STRUCT_TM_TM_ZONE) +#elif defined(HAVE_TM_GMTOFF) time_t t; struct tm tm = (struct tm) { 0 }; diff --git a/monetdb_config.h.in b/monetdb_config.h.in --- a/monetdb_config.h.in +++ b/monetdb_config.h.in @@ -166,6 +166,7 @@ #cmakedefine HAVE_SYSCONF 1 #cmakedefine HAVE_TASK_INFO 1 #cmakedefine HAVE_TIMES 1 +#cmakedefine HAVE_TM_GMTOFF 1 #cmakedefine HAVE_UNAME 1 // #cmakedefine HAVE_SEMTIMEDOP #cmakedefine HAVE_PTHREAD_KILL 1 _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org