diff --git a/testing/test-RRULE-v2.php b/testing/test-RRULE-v2.php index d8ab2a76..756faf43 100755 --- a/testing/test-RRULE-v2.php +++ b/testing/test-RRULE-v2.php @@ -12,6 +12,15 @@ $c->dbg = array(); require_once("RRule.php"); require_once('AwlQuery.php'); +# Check database timezone +$qry = new AwlQuery(); +$qry->QDo("SHOW TIMEZONE"); +$row = $qry->Fetch(); + +$initial_tz = $row->TimeZone; + +echo "Database Time Zone: $initial_tz\n"; + @header("Content-Type: text/plain; charset=UTF-8"); echo <<recur = $recur; $this->result_description = $result_description; $this->result_limit = 30; + + if ( preg_match('/^.*? (.*)$/', $this->dtstart, $matches) ) { + $this->tz = $matches[1]; + } } function PHPTest() { @@ -50,10 +63,25 @@ class RRuleTest { } function SQLTest() { + $qry = new AwlQuery; + global $initial_tz; + + # This is a hack to get the output time to be in "local time" so that we + # get the same time out of the PHP code to allow the diff between the + # results to work. + $changed_tz = 0; + if (isset($this->tz) && $this->tz != $initial_tz) { + echo "Setting database time zone to: $this->tz\n"; + $qry->QDo("SET TIMEZONE TO :tz", array( ':tz' => $this->tz )); + $changed_tz = 1; + } + $result = ''; $sql = "SELECT event_instances::timestamp AS event_date FROM event_instances(:dtstart,:rrule) LIMIT ".$this->result_limit; $start = microtime(true); - $qry = new AwlQuery($sql, array( ':dtstart' => $this->dtstart, ':rrule' => $this->recur) ); + $qry->SetSql($sql); + $qry->Bind(array( ':dtstart' => $this->dtstart, ':rrule' => $this->recur) ); + // printf( "%s\n", $qry->querystring); if ( $qry->Exec("test") && $qry->rows() > 0 ) { $i = 0; @@ -63,6 +91,11 @@ class RRuleTest { } } $this->SQL_time = microtime(true) - $start; + + if ($changed_tz) { + $qry->QDo("SET TIMEZONE TO '$initial_tz'"); + } + return $result; } }