]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Temporal.php
Remove get_server() in favor of Search::getGlobalDirectory()
[friendica.git] / src / Util / Temporal.php
index b6392d72fc043f9e853d3e6315390e743c96a100..6a331104eec74caaf50f62de5c551aedb85c52a4 100644 (file)
@@ -8,7 +8,6 @@ namespace Friendica\Util;
 
 use DateTime;
 use DateTimeZone;
-use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\Renderer;
@@ -99,12 +98,13 @@ class Temporal
         * arguments follow convention as other field_* template array:
         * 'name', 'label', $value, 'help'
         *
-        * @param string $name Name of the selector
-        * @param string $label Label for the selector
+        * @param string $name    Name of the selector
+        * @param string $label   Label for the selector
         * @param string $current Timezone
-        * @param string $help Help text
+        * @param string $help    Help text
         *
         * @return string Parsed HTML
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function getTimezoneField($name = 'timezone', $label = '', $current = 'America/Los_Angeles', $help = '')
        {
@@ -122,12 +122,12 @@ class Temporal
         * @brief Wrapper for date selector, tailored for use in birthday fields.
         *
         * @param string $dob Date of Birth
+        * @param string $timezone
         * @return string Formatted HTML
+        * @throws \Exception
         */
-       public static function getDateofBirthField($dob)
+       public static function getDateofBirthField(string $dob, string $timezone = 'UTC')
        {
-               $a = \get_app();
-
                list($year, $month, $day) = sscanf($dob, '%4d-%2d-%2d');
 
                if ($dob < '0000-01-01') {
@@ -136,7 +136,7 @@ class Temporal
                        $value = DateTimeFormat::utc(($year > 1000) ? $dob : '1000-' . $month . '-' . $day, 'Y-m-d');
                }
 
-               $age = (intval($value) ? self::getAgeByTimezone($value, $a->user["timezone"], $a->user["timezone"]) : "");
+               $age = (intval($value) ? self::getAgeByTimezone($value, $timezone, $timezone) : "");
 
                $tpl = Renderer::getMarkupTemplate("field_input.tpl");
                $o = Renderer::replaceMacros($tpl,
@@ -157,12 +157,13 @@ class Temporal
        /**
         * @brief Returns a date selector
         *
-        * @param string $min     Unix timestamp of minimum date
-        * @param string $max     Unix timestap of maximum date
-        * @param string $default Unix timestamp of default date
-        * @param string $id      ID and name of datetimepicker (defaults to "datetimepicker")
+        * @param DateTime $min     Minimum date
+        * @param DateTime $max     Maximum date
+        * @param DateTime $default Default date
+        * @param string   $id      ID and name of datetimepicker (defaults to "datetimepicker")
         *
         * @return string Parsed HTML output.
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function getDateField($min, $max, $default, $id = 'datepicker')
        {
@@ -177,6 +178,7 @@ class Temporal
         * @param string $id ID and name of datetimepicker (defaults to "timepicker")
         *
         * @return string Parsed HTML output.
+        * @throws \Exception
         */
        public static function getTimeField($h, $m, $id = 'timepicker')
        {
@@ -189,6 +191,7 @@ class Temporal
         * @param DateTime $minDate     Minimum date
         * @param DateTime $maxDate     Maximum date
         * @param DateTime $defaultDate Default date
+        * @param          $label
         * @param string   $id          Id and name of datetimepicker (defaults to "datetimepicker")
         * @param bool     $pickdate    true to show date picker (default)
         * @param bool     $picktime    true to show time picker (default)
@@ -198,7 +201,8 @@ class Temporal
         *
         * @return string Parsed HTML output.
         *
-        * @todo Once browser support is better this could probably be replaced with
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @todo  Once browser support is better this could probably be replaced with
         * native HTML5 date picker.
         */
        public static function getDateTimeField(
@@ -348,11 +352,12 @@ class Temporal
         * and become a year older. If you wish me happy birthday on January 1
         * (San Bruno time), you'll be a day late.
         *
-        * @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 $owner_tz  (optional) Timezone of the person of interest
         * @param string $viewer_tz (optional) Timezone of the person viewing
         *
         * @return int Age in years
+        * @throws \Exception
         */
        public static function getAgeByTimezone($dob, $owner_tz = '', $viewer_tz = '')
        {
@@ -404,6 +409,7 @@ class Temporal
         * @param int $m Month (1=January, 12=December)
         *
         * @return string day 0 = Sunday through 6 = Saturday
+        * @throws \Exception
         */
        private static function getFirstDayInMonth($y, $m)
        {
@@ -420,14 +426,15 @@ class Temporal
         * altering td class.
         * Months count from 1.
         *
-        * @param int    $y Year
-        * @param int    $m Month
+        * @param int    $y     Year
+        * @param int    $m     Month
         * @param array  $links (default null)
         * @param string $class
         *
         * @return string
         *
-        * @todo Provide (prev, next) links, define class variations for different size calendars
+        * @throws \Exception
+        * @todo  Provide (prev, next) links, define class variations for different size calendars
         */
        public static function getCalendarTable($y = 0, $m = 0, $links = null, $class = '')
        {