LP#1485374: call tzset() after setting timezone
authorGalen Charlton <gmc@esilibrary.com>
Wed, 3 Feb 2016 22:50:58 +0000 (17:50 -0500)
committerJason Stephenson <jason@sigio.com>
Sun, 11 Sep 2016 14:12:26 +0000 (10:12 -0400)
Testing shows this to be needed to make strftime()
return the time in the client's time zone.

This is a bit confusing, however, as strftime per
POSIX should be acting as if it always calls tzset()
when doing formatting that involves the local timezone.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Jason Stephenson <jason@sigio.com>
Open-ILS/src/c-apps/oils_sql.c

index 9ea52f6..c33a3af 100644 (file)
@@ -859,6 +859,7 @@ int beginTransaction( osrfMethodContext* ctx ) {
 
        if (tz) {
                setenv("TZ",tz,1);
+               tzset();
                dbi_result tz_res = dbi_conn_queryf( writehandle, "SET LOCAL timezone TO '%s'; -- cstore", tz );
                if( !tz_res ) {
                        osrfLogError( OSRF_LOG_MARK, "%s: Error setting timezone %s", modulename, tz);
@@ -871,6 +872,7 @@ int beginTransaction( osrfMethodContext* ctx ) {
                }
        } else {
                unsetenv("TZ");
+               tzset();
                dbi_result res = dbi_conn_queryf( writehandle, "SET timezone TO DEFAULT; -- no tz" );
                if( !res ) {
                        osrfLogError( OSRF_LOG_MARK, "%s: Error resetting timezone", modulename);
@@ -5890,6 +5892,7 @@ static jsonObject* doFieldmapperSearch( osrfMethodContext* ctx, osrfHash* class_
        if (!getXactId(ctx)) {
                if (tz) {
                        setenv("TZ",tz,1);
+                       tzset();
                        dbi_result tz_res = dbi_conn_queryf( writehandle, "SET timezone TO '%s'; -- cstore", tz );
                        if( !tz_res ) {
                                osrfLogError( OSRF_LOG_MARK, "%s: Error setting timezone %s", modulename, tz);
@@ -5904,6 +5907,7 @@ static jsonObject* doFieldmapperSearch( osrfMethodContext* ctx, osrfHash* class_
                        }
                } else {
                        unsetenv("TZ");
+                       tzset();
                        dbi_result res = dbi_conn_queryf( writehandle, "SET timezone TO DEFAULT; -- cstore" );
                        if( !res ) {
                                osrfLogError( OSRF_LOG_MARK, "%s: Error resetting timezone", modulename);