diff --git a/do_postgres/ext/do_postgres_ext.c b/do_postgres/ext/do_postgres_ext.c index e410d53..da6b866 100755 --- a/do_postgres/ext/do_postgres_ext.c +++ b/do_postgres/ext/do_postgres_ext.c @@ -118,10 +118,24 @@ static VALUE timezone_to_offset(const char sign, int hour_offset, int minute_off return seconds_to_offset(seconds); } +// Culled from Postgres' pgtz.c +static int get_local_timezone_offset(struct tm * tm) { +#if defined(HAVE_STRUCT_TM_TM_ZONE) + return tm->tm_gmtoff; +#else +#ifndef __CYGWIN__ + return -timezone; +#else + return -_timezone; +#endif +#endif +} + static VALUE parse_date_time(const char *date) { VALUE ajd, offset; int year, month, day, hour, min, sec, usec, hour_offset, minute_offset; + int gmt_offset; int jd; char sign; do_int64 num, den; @@ -155,9 +169,12 @@ static VALUE parse_date_time(const char *date) { // TODO: Refactor the following few lines to do the calculation with the *seconds* // value instead of having to do the hour/minute math - hour_offset = abs(timeinfo->tm_gmtoff) / 3600; - minute_offset = abs(timeinfo->tm_gmtoff) % 3600 / 60; - sign = timeinfo->tm_gmtoff < 0 ? '-' : '+'; + + gmt_offset = get_local_timezone_offset(timeinfo); + + hour_offset = abs(gmt_offset) / 3600; + minute_offset = abs(gmt_offset) % 3600 / 60; + sign = gmt_offset < 0 ? '-' : '+'; } else { // Something went terribly wrong rb_raise(ePostgresError, "Couldn't parse date: %s", date);