LP#838525 libdbi DATE types translated via gmtime
authorBill Erickson <berickxx@gmail.com>
Tue, 29 Sep 2015 16:10:53 +0000 (12:10 -0400)
committerMike Rylander <mrylander@gmail.com>
Thu, 1 Oct 2015 18:47:18 +0000 (14:47 -0400)
libdbi assumes a date (w/ no time or timezone) is GMT.  Parse the date
via gmtime() instead of localtime() to ensure the date returned to the
caller matches the date in the DB.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/c-apps/oils_execsql.c
Open-ILS/src/c-apps/oils_sql.c

index 4c10ddc..7491dd3 100644 (file)
@@ -166,7 +166,7 @@ static jsonObject* get_date_column( dbi_result result, int col_idx ) {
                gmtime_r( &timestamp, &gmdt );
                strftime( timestring, sizeof( timestring ), "%T", &gmdt );
        } else if( !( attr & DBI_DATETIME_TIME )) {
-               localtime_r( &timestamp, &gmdt );
+               gmtime_r( &timestamp, &gmdt );
                strftime( timestring, sizeof( timestring ), "%F", &gmdt );
        } else {
                localtime_r( &timestamp, &gmdt );
index 0d3205c..8169f42 100644 (file)
@@ -6683,7 +6683,7 @@ static jsonObject* oilsMakeFieldmapperFromResult( dbi_result result, osrfHash* m
                                                gmtime_r( &_tmp_dt, &gmdt );
                                                strftime( dt_string, sizeof( dt_string ), "%T", &gmdt );
                                        } else if( !( attr & DBI_DATETIME_TIME )) {
-                                               localtime_r( &_tmp_dt, &gmdt );
+                                               gmtime_r( &_tmp_dt, &gmdt );
                                                strftime( dt_string, sizeof( dt_string ), "%04Y-%m-%d", &gmdt );
                                        } else {
                                                localtime_r( &_tmp_dt, &gmdt );
@@ -6769,7 +6769,7 @@ static jsonObject* oilsMakeJSONFromResult( dbi_result result ) {
                                                gmtime_r( &_tmp_dt, &gmdt );
                                                strftime( dt_string, sizeof( dt_string ), "%T", &gmdt );
                                        } else if( !( attr & DBI_DATETIME_TIME )) {
-                                               localtime_r( &_tmp_dt, &gmdt );
+                                               gmtime_r( &_tmp_dt, &gmdt );
                                                strftime( dt_string, sizeof( dt_string ), "%04Y-%m-%d", &gmdt );
                                        } else {
                                                localtime_r( &_tmp_dt, &gmdt );