From d0fffe490af1ff05bb3b83b31c622ae4c504ac9e Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Thu, 26 Sep 2013 14:24:08 +0200 Subject: [PATCH] Set the default timezone to the database as well as for PHP. --- htdocs/always.php | 15 ++++++++++----- inc/always.php.in | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/htdocs/always.php b/htdocs/always.php index ca23ad95..136bd839 100644 --- a/htdocs/always.php +++ b/htdocs/always.php @@ -42,10 +42,13 @@ function early_exception_handler($e) { } set_exception_handler('early_exception_handler'); -$c->default_timezone = ini_get('date.timezone'); -if ( empty($c->default_timezone) ) { - $c->default_timezone = 'UTC'; - date_default_timezone_set('UTC'); +$c->default_timezone = ini_get ( 'date.timezone' ); +if (empty ( $c->default_timezone )) { + if (isset ( $_SERVER ['HTTP_X_DAVICAL_TESTCASE'] )) { + $c->default_timezone = 'Pacific/Auckland'; + } + $c->default_timezone = 'UTC'; + date_default_timezone_set ( 'UTC' ); } // Default some of the configurable values @@ -231,7 +234,9 @@ if ( $qry->Exec('always',__LINE__,__FILE__) && $row = $qry->Fetch() ) { $c->messages[] = sprintf( 'Database schema needs upgrading. Current: %d.%d.%d, Desired: %d.%d.%d', $row->schema_major, $row->schema_minor, $row->schema_patch, $c->want_dbversion[0], $c->want_dbversion[1], $c->want_dbversion[2]); } - if ( isset($_SERVER['HTTP_X_DAVICAL_TESTCASE']) ) $qry->QDo('SET TIMEZONE TO \'Pacific/Auckland\''); + if ( isset($c->default_timezone) ) { + $qry->QDo('SET TIMEZONE TO ?', $c->default_timezone ); + } } require_once('Principal.php'); diff --git a/inc/always.php.in b/inc/always.php.in index c7e90312..57068532 100644 --- a/inc/always.php.in +++ b/inc/always.php.in @@ -42,10 +42,13 @@ function early_exception_handler($e) { } set_exception_handler('early_exception_handler'); -$c->default_timezone = ini_get('date.timezone'); -if ( empty($c->default_timezone) ) { - $c->default_timezone = 'UTC'; - date_default_timezone_set('UTC'); +$c->default_timezone = ini_get ( 'date.timezone' ); +if (empty ( $c->default_timezone )) { + if (isset ( $_SERVER ['HTTP_X_DAVICAL_TESTCASE'] )) { + $c->default_timezone = 'Pacific/Auckland'; + } + $c->default_timezone = 'UTC'; + date_default_timezone_set ( 'UTC' ); } // Default some of the configurable values @@ -231,7 +234,9 @@ if ( $qry->Exec('always',__LINE__,__FILE__) && $row = $qry->Fetch() ) { $c->messages[] = sprintf( 'Database schema needs upgrading. Current: %d.%d.%d, Desired: %d.%d.%d', $row->schema_major, $row->schema_minor, $row->schema_patch, $c->want_dbversion[0], $c->want_dbversion[1], $c->want_dbversion[2]); } - if ( isset($_SERVER['HTTP_X_DAVICAL_TESTCASE']) ) $qry->QDo('SET TIMEZONE TO \'Pacific/Auckland\''); + if ( isset($c->default_timezone) ) { + $qry->QDo('SET TIMEZONE TO ?', $c->default_timezone ); + } } require_once('Principal.php');