Skip to content

Commit 449ec1c

Browse files
committed
Add timezone-option.
git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1687 44740490-163a-0410-bde0-09ae8108e29a
1 parent 8635ad4 commit 449ec1c

4 files changed

Lines changed: 64 additions & 13 deletions

File tree

config-templates/config.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,16 @@
7171
*/
7272
'technicalcontact_name' => 'Administrator',
7373
'technicalcontact_email' => 'na@example.org',
74-
74+
75+
/*
76+
* The timezone of the server. This option should be set to the timezone you want
77+
* simpleSAMLphp to report the time in. The default is to guess the timezone based
78+
* on your system timezone.
79+
*
80+
* See this page for a list of valid timezones: http://php.net/manual/en/timezones.php
81+
*/
82+
'timezone' => NULL,
83+
7584
/*
7685
* Logging.
7786
*

docs/simplesamlphp-install.txt

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@ file, `config.php`, right away:
166166

167167
'language.default' => 'no',
168168

169+
-
170+
Set the timezone which you use:
171+
172+
'timezone' => 'Europe/Oslo',
173+
174+
* [List of Supported Timezones at php.net](http://php.net/manual/en/timezones.php)
175+
169176

170177
Configuring PHP
171178
---------------
@@ -175,18 +182,6 @@ Configuring PHP
175182
Some parts of simpleSAMLphp will allow you to send e-mails. In example sending error reports to technical admin, as well as sending in metadata to the federation administrators. If you want to make use of this functionality, you should make sure your PHP installation is configured to be able to send e-mails. It's a common problem that PHP is not configured to send e-mails properly. The configuration differs from system to system. On UNIX, PHP is using sendmail, on Windows SMTP.
176183

177184

178-
### Configuring time zone in PHP
179-
180-
Some default installations of PHP does not include a timezone setting. The result is that a lot of warnings is thrown in the log files, which may be annoying. Therefore we reccomend to always set a timezone in the `php.ini` configuration file. In example like this:
181-
182-
[Date]
183-
; Defines the default timezone used by the date functions
184-
date.timezone = Europe/Oslo
185-
186-
187-
* [List of Supported Timezones at php.net](http://php.net/manual/en/timezones.php)
188-
189-
190185
Enable modules
191186
--------------
192187

lib/SimpleSAML/Utilities.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,6 +1920,50 @@ public static function validateCA($certificate, $caFile) {
19201920
SimpleSAML_Logger::debug('Successfully validated certificate.');
19211921
}
19221922

1923+
1924+
/**
1925+
* Initialize the timezone.
1926+
*
1927+
* This function should be called before any calls to date().
1928+
*/
1929+
public static function initTimezone() {
1930+
static $initialized = FALSE;
1931+
1932+
if ($initialized) {
1933+
return;
1934+
}
1935+
1936+
$initialized = TRUE;
1937+
1938+
$globalConfig = SimpleSAML_Configuration::getInstance();
1939+
1940+
$timezone = $globalConfig->getString('timezone', NULL);
1941+
if ($timezone !== NULL) {
1942+
if (!date_default_timezone_set($timezone)) {
1943+
throw new SimpleSAML_Error_Exception('Invalid timezone set in the \'timezone\'-option in config.php.');
1944+
}
1945+
return;
1946+
}
1947+
1948+
/* We don't have a timezone configured. */
1949+
1950+
/*
1951+
* The date_default_timezone_get()-function is likely to cause a warning.
1952+
* Since we have a custom error handler which logs the errors with a backtrace,
1953+
* this error will be logged even if we prefix the function call with '@'.
1954+
* Instead we temporarily replace the error handler.
1955+
*/
1956+
function ignoreError() {
1957+
/* Don't do anything with this error. */
1958+
return TRUE;
1959+
}
1960+
set_error_handler('ignoreError');
1961+
$serverTimezone = date_default_timezone_get();
1962+
restore_error_handler();
1963+
1964+
/* Set the timezone to the default. */
1965+
date_default_timezone_set($serverTimezone);
1966+
}
19231967
}
19241968

19251969
?>

www/_include.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,7 @@ function __toString() {
9494
/* Make sure that the session is initialized before any output. */
9595
SimpleSAML_Session::getInstance();
9696

97+
/* Set the timezone. */
98+
SimpleSAML_Utilities::initTimezone();
99+
97100
?>

0 commit comments

Comments
 (0)