From: Michael <heluecht@pirati.ca>
Date: Sat, 24 Jul 2021 21:16:53 +0000 (+0000)
Subject: Use getter/setter for timezone value
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=866dbf9f89cd14b2ec6fdfc9534627bdcecc39a4;p=friendica.git

Use getter/setter for timezone value
---

diff --git a/mod/ping.php b/mod/ping.php
index 146e7e75b5..93c579e0a6 100644
--- a/mod/ping.php
+++ b/mod/ping.php
@@ -230,7 +230,7 @@ function ping_init(App $a)
 			$all_events = count($ev);
 
 			if ($all_events) {
-				$str_now = DateTimeFormat::timezoneNow($a->timezone, 'Y-m-d');
+				$str_now = DateTimeFormat::timezoneNow($a->getTimeZone(), 'Y-m-d');
 				foreach ($ev as $x) {
 					$bd = false;
 					if ($x['type'] === 'birthday') {
@@ -239,7 +239,7 @@ function ping_init(App $a)
 					} else {
 						$events ++;
 					}
-					if (DateTimeFormat::convert($x['start'], ((intval($x['adjust'])) ? $a->timezone : 'UTC'), 'UTC', 'Y-m-d') === $str_now) {
+					if (DateTimeFormat::convert($x['start'], ((intval($x['adjust'])) ? $a->getTimeZone() : 'UTC'), 'UTC', 'Y-m-d') === $str_now) {
 						$all_events_today ++;
 						if ($bd) {
 							$birthdays_today ++;
diff --git a/src/App.php b/src/App.php
index e0fd2ef8fc..d71acef632 100644
--- a/src/App.php
+++ b/src/App.php
@@ -62,7 +62,6 @@ class App
 	public $argv;
 	/** @deprecated 2019.09 - use App\Arguments->getArgc() */
 	public $argc;
-	public $timezone;
 	public $theme_info = [];
 	// Allow themes to control internal parameters
 	// by changing App values in theme.php
@@ -72,6 +71,7 @@ class App
 	public $theme_events_in_profile = true;
 	public $queue;
 
+	private $timezone = '';
 	private $profile_owner = 0;
 	private $contact_id    = 0;
 
@@ -172,6 +172,27 @@ class App
 		return $this->contact_id;
 	}
 
+	/**
+	 * Set the timezone
+	 * 
+	 * @param int $timezone 
+	 * @return void 
+	 */
+	public function setTimeZone(string $timezone)
+	{
+		$this->timezone = $timezone;
+	}
+
+	/**
+	 * Get the timezone
+	 *
+	 * @return int 
+	 */
+	public function getTimeZone():string
+	{
+		return $this->timezone;
+	}
+
 	/**
 	 * Returns the current config cache of this node
 	 *
diff --git a/src/Model/Profile.php b/src/Model/Profile.php
index 62df630dc8..1c75201c97 100644
--- a/src/Model/Profile.php
+++ b/src/Model/Profile.php
@@ -544,7 +544,7 @@ class Profile
 
 					$rr['link'] = Contact::magicLinkById($rr['cid']);
 					$rr['title'] = $rr['name'];
-					$rr['date'] = DI::l10n()->getDay(DateTimeFormat::convert($rr['start'], $a->timezone, 'UTC', $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . DI::l10n()->t('[today]') : '');
+					$rr['date'] = DI::l10n()->getDay(DateTimeFormat::convert($rr['start'], $a->getTimeZone(), 'UTC', $rr['adjust'] ? $bd_format : $bd_short)) . (($today) ? ' ' . DI::l10n()->t('[today]') : '');
 					$rr['startime'] = null;
 					$rr['today'] = $today;
 				}
@@ -603,8 +603,8 @@ class Profile
 					$total++;
 				}
 
-				$strt = DateTimeFormat::convert($rr['start'], $rr['adjust'] ? $a->timezone : 'UTC', 'UTC', 'Y-m-d');
-				if ($strt === DateTimeFormat::timezoneNow($a->timezone, 'Y-m-d')) {
+				$strt = DateTimeFormat::convert($rr['start'], $rr['adjust'] ? $a->getTimeZone() : 'UTC', 'UTC', 'Y-m-d');
+				if ($strt === DateTimeFormat::timezoneNow($a->getTimeZone(), 'Y-m-d')) {
 					$istoday = true;
 				}
 
@@ -619,17 +619,17 @@ class Profile
 					$description = DI::l10n()->t('[No description]');
 				}
 
-				$strt = DateTimeFormat::convert($rr['start'], $rr['adjust'] ? $a->timezone : 'UTC');
+				$strt = DateTimeFormat::convert($rr['start'], $rr['adjust'] ? $a->getTimeZone() : 'UTC');
 
-				if (substr($strt, 0, 10) < DateTimeFormat::timezoneNow($a->timezone, 'Y-m-d')) {
+				if (substr($strt, 0, 10) < DateTimeFormat::timezoneNow($a->getTimeZone(), 'Y-m-d')) {
 					continue;
 				}
 
-				$today = ((substr($strt, 0, 10) === DateTimeFormat::timezoneNow($a->timezone, 'Y-m-d')) ? true : false);
+				$today = ((substr($strt, 0, 10) === DateTimeFormat::timezoneNow($a->getTimeZone(), 'Y-m-d')) ? true : false);
 
 				$rr['title'] = $title;
 				$rr['description'] = $description;
-				$rr['date'] = DI::l10n()->getDay(DateTimeFormat::convert($rr['start'], $rr['adjust'] ? $a->timezone : 'UTC', 'UTC', $bd_format)) . (($today) ? ' ' . DI::l10n()->t('[today]') : '');
+				$rr['date'] = DI::l10n()->getDay(DateTimeFormat::convert($rr['start'], $rr['adjust'] ? $a->getTimeZone() : 'UTC', 'UTC', $bd_format)) . (($today) ? ' ' . DI::l10n()->t('[today]') : '');
 				$rr['startime'] = $strt;
 				$rr['today'] = $today;
 
diff --git a/src/Security/Authentication.php b/src/Security/Authentication.php
index 3ad9a28999..d93f7f9dc5 100644
--- a/src/Security/Authentication.php
+++ b/src/Security/Authentication.php
@@ -307,7 +307,7 @@ class Authentication
 
 		if (strlen($user_record['timezone'])) {
 			date_default_timezone_set($user_record['timezone']);
-			$a->timezone = $user_record['timezone'];
+			$a->setTimeZone($user_record['timezone']);
 		}
 
 		$contact = $this->dba->selectFirst('contact', ['id'], ['uid' => $user_record['uid'], 'self' => true]);