@@ -75,25 +75,23 @@ class Time extends DateTime
7575 */
7676 public function __construct (?string $ time = null , $ timezone = null , ?string $ locale = null )
7777 {
78- // If no locale was provided, grab it from Locale (set by IncomingRequest for web requests)
79- $ this ->locale = ! empty ($ locale ) ? $ locale : Locale::getDefault ();
78+ $ this ->locale = $ locale ?: Locale::getDefault ();
8079
81- // If a test instance has been provided, use it instead.
82- if ($ time === null && static ::$ testNow instanceof self) {
83- if (empty ($ timezone )) {
84- $ timezone = static ::$ testNow ->getTimezone ();
85- }
80+ $ time = $ time ?? '' ;
8681
87- $ time = static ::$ testNow ->toDateTimeString ();
82+ // If a test instance has been provided, use it instead.
83+ if ($ time === '' && static ::$ testNow instanceof self) {
84+ $ timezone = $ timezone ?: static ::$ testNow ->getTimezone ();
85+ $ time = (string ) static ::$ testNow ->toDateTimeString ();
8886 }
8987
90- $ timezone = ! empty ( $ timezone) ? $ timezone : date_default_timezone_get ();
88+ $ timezone = $ timezone ? : date_default_timezone_get ();
9189 $ this ->timezone = $ timezone instanceof DateTimeZone ? $ timezone : new DateTimeZone ($ timezone );
9290
9391 // If the time string was a relative string (i.e. 'next Tuesday')
9492 // then we need to adjust the time going in so that we have a current
9593 // timezone to work with.
96- if (! empty ( $ time) && ( is_string ( $ time ) && static ::hasRelativeKeywords ($ time) )) {
94+ if ($ time !== '' && static ::hasRelativeKeywords ($ time )) {
9795 $ instance = new DateTime ('now ' , $ this ->timezone );
9896 $ instance ->modify ($ time );
9997 $ time = $ instance ->format ('Y-m-d H:i:s ' );
0 commit comments