]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Temporal.php
Catch exceptions for Worker::AddContact()
[friendica.git] / src / Util / Temporal.php
index ef27b54b2d00547e292a629a7164861b69ad3842..e6d0f207df71963d48ae28f140232e3ddcb9642b 100644 (file)
@@ -1,7 +1,22 @@
 <?php
-
 /**
- * @file src/Util/Temporal.php
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
  */
 
 namespace Friendica\Util;
@@ -210,7 +225,7 @@ class Temporal
        public static function getDateTimeField(
                DateTime $minDate,
                DateTime $maxDate,
-               DateTime $defaultDate,
+               DateTime $defaultDate = null,
                $label,
                $id       = 'datetimepicker',
                $pickdate = true,
@@ -256,7 +271,11 @@ class Temporal
                                $id,
                                $label,
                                $input_text,
-                               '',
+                               DI::l10n()->t(
+                                       'Time zone: <strong>%s</strong> <a href="%s">Change in Settings</a>',
+                                       str_replace('_', ' ', DI::app()->getTimeZone()) . ' (GMT ' . DateTimeFormat::localNow('P') . ')',
+                                       DI::baseUrl() . '/settings'
+                               ),
                                $required ? '*' : '',
                                'placeholder="' . $readable_format . '"'
                        ],
@@ -269,7 +288,7 @@ class Temporal
                                'lang' => $lang,
                                'minfrom' => $minfrom,
                                'maxfrom' => $maxfrom,
-                       ]
+                       ],
                ]);
 
                return $o;
@@ -345,28 +364,24 @@ class Temporal
         * Returns the age in years, given a date of birth and the timezone of the person
         * whose date of birth is provided.
         *
-        * @param string $dob       Date of Birth
-        * @param string $owner_tz  (optional) Timezone of the person of interest
+        * @param string $dob      Date of Birth
+        * @param string $timezone Timezone of the person of interest
         *
         * @return int Age in years
         * @throws \Exception
         */
-       public static function getAgeByTimezone($dob, $owner_tz = '')
+       public static function getAgeByTimezone(string $dob, string $timezone): int
        {
                if (!intval($dob)) {
                        return 0;
                }
 
-               if (!$owner_tz) {
-                       $owner_tz = date_default_timezone_get();
-               }
-
-               $birthdate = new DateTime($dob . ' 00:00:00', new DateTimeZone($owner_tz));
+               $birthdate = new DateTime($dob . ' 00:00:00', new DateTimeZone($timezone));
                $currentDate = new DateTime('now', new DateTimeZone('UTC'));
 
                $interval = $birthdate->diff($currentDate);
 
-               return $interval->format('%y');
+               return (int) $interval->format('%y');
        }
 
        /**