From 5f40f0cc685ee8168972ad4b4bea94c3ae47b880 Mon Sep 17 00:00:00 2001
From: Jaime Perez Crespo <jaime.perez@uninett.no>
Date: Mon, 20 Apr 2015 15:18:52 +0200
Subject: [PATCH] Move SimpleSAML_Utilities::initTimezone() to
 SimpleSAML\Utils\Time::initTimezone(). Deprecate the former.

---
 lib/SimpleSAML/Logger/LoggingHandlerFile.php |  2 +-
 lib/SimpleSAML/Utilities.php                 | 41 +-----------------
 lib/SimpleSAML/Utils/Time.php                | 45 ++++++++++++++++++++
 modules/statistics/bin/loganalyzer.php       |  2 +-
 www/_include.php                             |  2 +-
 5 files changed, 50 insertions(+), 42 deletions(-)

diff --git a/lib/SimpleSAML/Logger/LoggingHandlerFile.php b/lib/SimpleSAML/Logger/LoggingHandlerFile.php
index 9ed795e85..feab43770 100644
--- a/lib/SimpleSAML/Logger/LoggingHandlerFile.php
+++ b/lib/SimpleSAML/Logger/LoggingHandlerFile.php
@@ -56,7 +56,7 @@ class SimpleSAML_Logger_LoggingHandlerFile implements SimpleSAML_Logger_LoggingH
             }
         }
 
-        SimpleSAML_Utilities::initTimezone();
+        SimpleSAML\Utils\Time::initTimezone();
     }
 
 
diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index 2b825caef..87227ce38 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -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();
 	}
 
 	/**
diff --git a/lib/SimpleSAML/Utils/Time.php b/lib/SimpleSAML/Utils/Time.php
index 50d8f5b67..46dfb3398 100644
--- a/lib/SimpleSAML/Utils/Time.php
+++ b/lib/SimpleSAML/Utils/Time.php
@@ -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
diff --git a/modules/statistics/bin/loganalyzer.php b/modules/statistics/bin/loganalyzer.php
index 7ea016ecc..7186890f4 100755
--- a/modules/statistics/bin/loganalyzer.php
+++ b/modules/statistics/bin/loganalyzer.php
@@ -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;
diff --git a/www/_include.php b/www/_include.php
index 4b52a300b..37f0c883f 100644
--- a/www/_include.php
+++ b/www/_include.php
@@ -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();
-- 
GitLab