Skip to content
Snippets Groups Projects
Commit 5f40f0cc authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Move SimpleSAML_Utilities::initTimezone() to...

Move SimpleSAML_Utilities::initTimezone() to SimpleSAML\Utils\Time::initTimezone(). Deprecate the former.
parent e391cf63
No related branches found
No related tags found
No related merge requests found
......@@ -56,7 +56,7 @@ class SimpleSAML_Logger_LoggingHandlerFile implements SimpleSAML_Logger_LoggingH
}
}
SimpleSAML_Utilities::initTimezone();
SimpleSAML\Utils\Time::initTimezone();
}
......
......@@ -1376,47 +1376,10 @@ class SimpleSAML_Utilities {
/**
* Initialize the timezone.
*
* This function should be called before any calls to date().
* @deprecated This function will be removed in SSP 2.0. Please use SimpleSAML\Utils\Time::initTimezone() instead.
*/
public static function initTimezone() {
static $initialized = FALSE;
if ($initialized) {
return;
}
$initialized = TRUE;
$globalConfig = SimpleSAML_Configuration::getInstance();
$timezone = $globalConfig->getString('timezone', NULL);
if ($timezone !== NULL) {
if (!date_default_timezone_set($timezone)) {
throw new SimpleSAML_Error_Exception('Invalid timezone set in the \'timezone\'-option in config.php.');
}
return;
}
/* We don't have a timezone configured. */
/*
* The date_default_timezone_get()-function is likely to cause a warning.
* Since we have a custom error handler which logs the errors with a backtrace,
* this error will be logged even if we prefix the function call with '@'.
* Instead we temporarily replace the error handler.
*/
function ignoreError() {
/* Don't do anything with this error. */
return TRUE;
}
set_error_handler('ignoreError');
$serverTimezone = date_default_timezone_get();
restore_error_handler();
/* Set the timezone to the default. */
date_default_timezone_set($serverTimezone);
return SimpleSAML\Utils\Time::initTimezone();
}
/**
......
......@@ -26,4 +26,49 @@ class Time
}
return gmdate('Y-m-d\TH:i:s\Z', $instant);
}
/**
* Initialize the timezone.
*
* This function should be called before any calls to date().
*
* @author Olav Morken, UNINETT AS <olav.morken@uninett.no>
*/
public static function initTimezone()
{
static $initialized = false;
if ($initialized) {
return;
}
$initialized = true;
$globalConfig = \SimpleSAML_Configuration::getInstance();
$timezone = $globalConfig->getString('timezone', null);
if ($timezone !== null) {
if (!date_default_timezone_set($timezone)) {
throw new \SimpleSAML_Error_Exception('Invalid timezone set in the "timezone" option in config.php.');
}
return;
}
// we don't have a timezone configured
/*
* The date_default_timezone_get() function is likely to cause a warning.
* Since we have a custom error handler which logs the errors with a backtrace,
* this error will be logged even if we prefix the function call with '@'.
* Instead we temporarily replace the error handler.
*/
set_error_handler(function (){
return true;
});
$serverTimezone = date_default_timezone_get();
restore_error_handler();
// set the timezone to the default
date_default_timezone_set($serverTimezone);
}
}
\ No newline at end of file
......@@ -11,7 +11,7 @@ require_once($baseDir . '/lib/_autoload.php');
/* Initialize the configuration. */
SimpleSAML_Configuration::setConfigDir($baseDir . '/config');
SimpleSAML_Utilities::initTimezone();
SimpleSAML\Utils\Time::initTimezone();
$progName = array_shift($argv);
$debug = FALSE;
......
......@@ -106,6 +106,6 @@ if (!file_exists($configdir . '/config.php')) {
}
/* Set the timezone. */
SimpleSAML_Utilities::initTimezone();
SimpleSAML\Utils\Time::initTimezone();
/* Disable XML external entity loading explicitly. */
libxml_disable_entity_loader();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment