@@ -32,7 +32,7 @@ class Time {
3232 * @param int|string|null $date
3333 * @param string|null $timezone
3434 */
35- public function __construct ($ date = 'now ' , ? string $ timezone = 'UTC ' )
35+ public function __construct ($ date = 'now ' , $ timezone = 'UTC ' )
3636 {
3737 if (empty (self ::$ date )){
3838 self ::setDate ($ date );
@@ -69,11 +69,11 @@ static public function __callStatic($name, $args)
6969
7070 /**
7171 * Set the timezone.
72- * @param string $timezone
72+ * @param string|null $timezone
7373 *
7474 * @return $this
7575 */
76- static public function setTimezone (? string $ timezone = null )
76+ static public function setTimezone ($ timezone = null )
7777 {
7878 if (in_array ($ timezone , Country::timeZone ())){
7979 self ::$ timezone = $ timezone ;
@@ -83,7 +83,7 @@ static public function setTimezone(?string $timezone = null)
8383 }
8484
8585 // set timezone
86- date_default_timezone_set ($ timezone );
86+ date_default_timezone_set (self :: $ timezone );
8787
8888 return new self (self ::$ date , self ::$ timezone );
8989 }
@@ -172,7 +172,7 @@ static public function format(int|string $date)
172172 *
173173 * @return string
174174 */
175- static public function timestamp ($ date , ? string $ format = "Y-m-d H:i:s " )
175+ static public function timestamp ($ date , $ format = "Y-m-d H:i:s " )
176176 {
177177 if (is_string ($ date )){
178178 $ date = strtotime ($ date );
@@ -299,7 +299,7 @@ static public function getYear()
299299 *
300300 * @return mixed
301301 */
302- static public function timeDifference (? string $ mode = null )
302+ static public function timeDifference ($ mode = null )
303303 {
304304 $ now = new DateTime ('now ' , new DateTimeZone (self ::getTimezone ()));
305305 $ date = new DateTime ();
@@ -348,7 +348,7 @@ static public function greeting()
348348 *
349349 * @return string
350350 */
351- static public function timeAgo (? string $ mode = null )
351+ static public function timeAgo ($ mode = null )
352352 {
353353 $ minutes = self ::getMin ();
354354 $ seconds = self ::getSecond ();
@@ -419,7 +419,7 @@ static public function timeAgo(?string $mode = null)
419419 *
420420 * @return mixed
421421 */
422- static private function getText (? string $ mode = null )
422+ static private function getText ($ mode = null )
423423 {
424424 if (!defined ('TIME_TEXT ' )){
425425 self ::config ();
@@ -450,51 +450,20 @@ static private function nonExistMethod($method = null, $args = null)
450450 // convert to lowercase
451451 $ name = Str::lower ($ method );
452452
453- switch ($ name ) {
454- case in_array ($ name , ['tojs ' , 'jstimer ' ]):
455- $ method = 'toJsTimer ' ;
456- break ;
457-
458- case in_array ($ name , ['time ' , 'gettimes ' , 'gettime ' ]):
459- $ method = 'getDate ' ;
460- break ;
461-
462- case in_array ($ name , ['hours ' , 'hr ' , 'hrs ' , 'gethr ' , 'gethours ' ]):
463- $ method = 'getHour ' ;
464- break ;
465-
466- case in_array ($ name , ['getseconds ' , 'getsec ' , 'sec ' , 's ' ]):
467- $ method = 'getSecond ' ;
468- break ;
469-
470- case in_array ($ name , ['min ' , 'mins ' , 'getminute ' , 'getminutes ' , 'getmins ' ]):
471- $ method = 'getMin ' ;
472- break ;
473-
474- case in_array ($ name , ['getday ' , 'getdays ' , 'getd ' , 'day ' , 'days ' ]):
475- $ method = 'getDay ' ;
476- break ;
477-
478- case in_array ($ name , ['getweek ' , 'getweeks ' , 'getw ' ]):
479- $ method = 'getWeek ' ;
480- break ;
481-
482- case in_array ($ name , ['getmonths ' , 'getmonth ' , 'getm ' ]):
483- $ method = 'getMonth ' ;
484- break ;
485-
486- case in_array ($ name , ['getyr ' , 'getyears ' , 'getyear ' , 'year ' , 'years ' , 'yr ' , 'yrs ' , 'y ' ]):
487- $ method = 'getYear ' ;
488- break ;
489-
490- case $ name === 'greetings ' :
491- $ method = 'greeting ' ;
492- break ;
493-
494- default :
495- $ method = 'timeAgo ' ;
496- break ;
497- }
453+ // create correct method name
454+ $ method = match ($ name ) {
455+ 'greetings ' => 'greeting ' ,
456+ 'tojs ' , 'jstimer ' => 'toJsTimer ' ,
457+ 'time ' , 'gettimes ' , 'gettime ' => 'getDate ' ,
458+ 'hours ' , 'hr ' , 'hrs ' , 'gethr ' , 'gethours ' => 'getHour ' ,
459+ 'getseconds ' , 'getsec ' , 'sec ' , 's ' => 'getSecond ' ,
460+ 'min ' , 'mins ' , 'getminute ' , 'getminutes ' , 'getmins ' => 'getMin ' ,
461+ 'getday ' , 'getdays ' , 'getd ' , 'day ' , 'days ' => 'getDay ' ,
462+ 'getweek ' , 'getweeks ' , 'getw ' => 'getWeek ' ,
463+ 'getmonths ' , 'getmonth ' , 'getm ' => 'getMonth ' ,
464+ 'getyr ' , 'getyears ' , 'getyear ' , 'year ' , 'years ' , 'yr ' , 'yrs ' , 'y ' => 'getYear ' ,
465+ default => 'timeAgo '
466+ };
498467
499468 // create instance of new static self
500469 $ instance = new static (self ::$ date , self ::$ timezone );
0 commit comments