@@ -78,7 +78,7 @@ public function __construct(?string $time = null, $timezone = null, ?string $loc
78
78
$ time ??= '' ;
79
79
80
80
// If a test instance has been provided, use it instead.
81
- if ($ time === '' && static ::$ testNow instanceof self ) {
81
+ if ($ time === '' && static ::$ testNow instanceof static ) {
82
82
if ($ timezone !== null ) {
83
83
$ testNow = static ::$ testNow ->setTimezone ($ timezone );
84
84
$ time = $ testNow ->format ('Y-m-d H:i:s.u ' );
@@ -108,13 +108,13 @@ public function __construct(?string $time = null, $timezone = null, ?string $loc
108
108
*
109
109
* @param DateTimeZone|string|null $timezone
110
110
*
111
- * @return self
111
+ * @return static
112
112
*
113
113
* @throws Exception
114
114
*/
115
115
public static function now ($ timezone = null , ?string $ locale = null )
116
116
{
117
- return new self (null , $ timezone , $ locale );
117
+ return new static (null , $ timezone , $ locale );
118
118
}
119
119
120
120
/**
@@ -125,55 +125,55 @@ public static function now($timezone = null, ?string $locale = null)
125
125
*
126
126
* @param DateTimeZone|string|null $timezone
127
127
*
128
- * @return self
128
+ * @return static
129
129
*
130
130
* @throws Exception
131
131
*/
132
132
public static function parse (string $ datetime , $ timezone = null , ?string $ locale = null )
133
133
{
134
- return new self ($ datetime , $ timezone , $ locale );
134
+ return new static ($ datetime , $ timezone , $ locale );
135
135
}
136
136
137
137
/**
138
138
* Return a new time with the time set to midnight.
139
139
*
140
140
* @param DateTimeZone|string|null $timezone
141
141
*
142
- * @return self
142
+ * @return static
143
143
*
144
144
* @throws Exception
145
145
*/
146
146
public static function today ($ timezone = null , ?string $ locale = null )
147
147
{
148
- return new self (date ('Y-m-d 00:00:00 ' ), $ timezone , $ locale );
148
+ return new static (date ('Y-m-d 00:00:00 ' ), $ timezone , $ locale );
149
149
}
150
150
151
151
/**
152
152
* Returns an instance set to midnight yesterday morning.
153
153
*
154
154
* @param DateTimeZone|string|null $timezone
155
155
*
156
- * @return self
156
+ * @return static
157
157
*
158
158
* @throws Exception
159
159
*/
160
160
public static function yesterday ($ timezone = null , ?string $ locale = null )
161
161
{
162
- return new self (date ('Y-m-d 00:00:00 ' , strtotime ('-1 day ' )), $ timezone , $ locale );
162
+ return new static (date ('Y-m-d 00:00:00 ' , strtotime ('-1 day ' )), $ timezone , $ locale );
163
163
}
164
164
165
165
/**
166
166
* Returns an instance set to midnight tomorrow morning.
167
167
*
168
168
* @param DateTimeZone|string|null $timezone
169
169
*
170
- * @return self
170
+ * @return static
171
171
*
172
172
* @throws Exception
173
173
*/
174
174
public static function tomorrow ($ timezone = null , ?string $ locale = null )
175
175
{
176
- return new self (date ('Y-m-d 00:00:00 ' , strtotime ('+1 day ' )), $ timezone , $ locale );
176
+ return new static (date ('Y-m-d 00:00:00 ' , strtotime ('+1 day ' )), $ timezone , $ locale );
177
177
}
178
178
179
179
/**
@@ -182,7 +182,7 @@ public static function tomorrow($timezone = null, ?string $locale = null)
182
182
*
183
183
* @param DateTimeZone|string|null $timezone
184
184
*
185
- * @return self
185
+ * @return static
186
186
*
187
187
* @throws Exception
188
188
*/
@@ -196,7 +196,7 @@ public static function createFromDate(?int $year = null, ?int $month = null, ?in
196
196
*
197
197
* @param DateTimeZone|string|null $timezone
198
198
*
199
- * @return self
199
+ * @return static
200
200
*
201
201
* @throws Exception
202
202
*/
@@ -210,7 +210,7 @@ public static function createFromTime(?int $hour = null, ?int $minutes = null, ?
210
210
*
211
211
* @param DateTimeZone|string|null $timezone
212
212
*
213
- * @return self
213
+ * @return static
214
214
*
215
215
* @throws Exception
216
216
*/
@@ -231,7 +231,7 @@ public static function create(
231
231
$ minutes ??= 0 ;
232
232
$ seconds ??= 0 ;
233
233
234
- return new self (date ('Y-m-d H:i:s ' , strtotime ("{$ year }- {$ month }- {$ day } {$ hour }: {$ minutes }: {$ seconds }" )), $ timezone , $ locale );
234
+ return new static (date ('Y-m-d H:i:s ' , strtotime ("{$ year }- {$ month }- {$ day } {$ hour }: {$ minutes }: {$ seconds }" )), $ timezone , $ locale );
235
235
}
236
236
237
237
/**
@@ -242,7 +242,7 @@ public static function create(
242
242
* @param string $datetime
243
243
* @param DateTimeZone|string|null $timezone
244
244
*
245
- * @return self
245
+ * @return static
246
246
*
247
247
* @throws Exception
248
248
*/
@@ -253,7 +253,7 @@ public static function createFromFormat($format, $datetime, $timezone = null)
253
253
throw I18nException::forInvalidFormat ($ format );
254
254
}
255
255
256
- return new self ($ date ->format ('Y-m-d H:i:s.u ' ), $ timezone );
256
+ return new static ($ date ->format ('Y-m-d H:i:s.u ' ), $ timezone );
257
257
}
258
258
259
259
/**
@@ -265,7 +265,7 @@ public static function createFromFormat($format, $datetime, $timezone = null)
265
265
*/
266
266
public static function createFromTimestamp (float |int $ timestamp , $ timezone = null , ?string $ locale = null ): static
267
267
{
268
- $ time = new self ('@ ' . $ timestamp , 'UTC ' , $ locale );
268
+ $ time = new static ('@ ' . $ timestamp , 'UTC ' , $ locale );
269
269
270
270
$ timezone ??= 'UTC ' ;
271
271
@@ -275,7 +275,7 @@ public static function createFromTimestamp(float|int $timestamp, $timezone = nul
275
275
/**
276
276
* Takes an instance of DateTimeInterface and returns an instance of Time with it's same values.
277
277
*
278
- * @return self
278
+ * @return static
279
279
*
280
280
* @throws Exception
281
281
*/
@@ -284,13 +284,13 @@ public static function createFromInstance(DateTimeInterface $dateTime, ?string $
284
284
$ date = $ dateTime ->format ('Y-m-d H:i:s.u ' );
285
285
$ timezone = $ dateTime ->getTimezone ();
286
286
287
- return new self ($ date , $ timezone , $ locale );
287
+ return new static ($ date , $ timezone , $ locale );
288
288
}
289
289
290
290
/**
291
291
* Takes an instance of DateTime and returns an instance of Time with it's same values.
292
292
*
293
- * @return self
293
+ * @return static
294
294
*
295
295
* @throws Exception
296
296
*
@@ -300,7 +300,7 @@ public static function createFromInstance(DateTimeInterface $dateTime, ?string $
300
300
*/
301
301
public static function instance (DateTime $ dateTime , ?string $ locale = null )
302
302
{
303
- return self ::createFromInstance ($ dateTime , $ locale );
303
+ return static ::createFromInstance ($ dateTime , $ locale );
304
304
}
305
305
306
306
/**
@@ -345,9 +345,9 @@ public static function setTestNow($datetime = null, $timezone = null, ?string $l
345
345
346
346
// Convert to a Time instance
347
347
if (is_string ($ datetime )) {
348
- $ datetime = new self ($ datetime , $ timezone , $ locale );
349
- } elseif ($ datetime instanceof DateTimeInterface && ! $ datetime instanceof self ) {
350
- $ datetime = new self ($ datetime ->format ('Y-m-d H:i:s.u ' ), $ timezone );
348
+ $ datetime = new static ($ datetime , $ timezone , $ locale );
349
+ } elseif ($ datetime instanceof DateTimeInterface && ! $ datetime instanceof static ) {
350
+ $ datetime = new static ($ datetime ->format ('Y-m-d H:i:s.u ' ), $ timezone );
351
351
}
352
352
353
353
static ::$ testNow = $ datetime ;
@@ -475,7 +475,7 @@ public function getWeekOfYear(): string
475
475
public function getAge ()
476
476
{
477
477
// future dates have no age
478
- return max (0 , $ this ->difference (self ::now ())->getYears ());
478
+ return max (0 , $ this ->difference (static ::now ())->getYears ());
479
479
}
480
480
481
481
/**
@@ -532,7 +532,7 @@ public function getTimezoneName(): string
532
532
*
533
533
* @param int|string $value
534
534
*
535
- * @return self
535
+ * @return static
536
536
*
537
537
* @throws Exception
538
538
*/
@@ -546,7 +546,7 @@ public function setYear($value)
546
546
*
547
547
* @param int|string $value
548
548
*
549
- * @return self
549
+ * @return static
550
550
*
551
551
* @throws Exception
552
552
*/
@@ -568,7 +568,7 @@ public function setMonth($value)
568
568
*
569
569
* @param int|string $value
570
570
*
571
- * @return self
571
+ * @return static
572
572
*
573
573
* @throws Exception
574
574
*/
@@ -592,7 +592,7 @@ public function setDay($value)
592
592
*
593
593
* @param int|string $value
594
594
*
595
- * @return self
595
+ * @return static
596
596
*
597
597
* @throws Exception
598
598
*/
@@ -610,7 +610,7 @@ public function setHour($value)
610
610
*
611
611
* @param int|string $value
612
612
*
613
- * @return self
613
+ * @return static
614
614
*
615
615
* @throws Exception
616
616
*/
@@ -628,7 +628,7 @@ public function setMinute($value)
628
628
*
629
629
* @param int|string $value
630
630
*
631
- * @return self
631
+ * @return static
632
632
*
633
633
* @throws Exception
634
634
*/
@@ -646,7 +646,7 @@ public function setSecond($value)
646
646
*
647
647
* @param int $value
648
648
*
649
- * @return self
649
+ * @return static
650
650
*
651
651
* @throws Exception
652
652
*/
@@ -656,7 +656,7 @@ protected function setValue(string $name, $value)
656
656
657
657
$ {$ name } = $ value ;
658
658
659
- return self ::create (
659
+ return static ::create (
660
660
(int ) $ year ,
661
661
(int ) $ month ,
662
662
(int ) $ day ,
@@ -673,7 +673,7 @@ protected function setValue(string $name, $value)
673
673
*
674
674
* @param DateTimeZone|string $timezone
675
675
*
676
- * @return self
676
+ * @return static
677
677
*
678
678
* @throws Exception
679
679
*/
@@ -682,15 +682,15 @@ public function setTimezone($timezone)
682
682
{
683
683
$ timezone = $ timezone instanceof DateTimeZone ? $ timezone : new DateTimeZone ($ timezone );
684
684
685
- return self ::createFromInstance ($ this ->toDateTime ()->setTimezone ($ timezone ), $ this ->locale );
685
+ return static ::createFromInstance ($ this ->toDateTime ()->setTimezone ($ timezone ), $ this ->locale );
686
686
}
687
687
688
688
/**
689
689
* Returns a new instance with the date set to the new timestamp.
690
690
*
691
691
* @param int $timestamp
692
692
*
693
- * @return self
693
+ * @return static
694
694
*
695
695
* @throws Exception
696
696
*/
@@ -699,7 +699,7 @@ public function setTimestamp($timestamp)
699
699
{
700
700
$ time = date ('Y-m-d H:i:s ' , $ timestamp );
701
701
702
- return self ::parse ($ time , $ this ->timezone , $ this ->locale );
702
+ return static ::parse ($ time , $ this ->timezone , $ this ->locale );
703
703
}
704
704
705
705
// --------------------------------------------------------------------
@@ -1085,7 +1085,7 @@ public function difference($testTime, ?string $timezone = null)
1085
1085
if (is_string ($ testTime )) {
1086
1086
$ timezone = ($ timezone !== null ) ? new DateTimeZone ($ timezone ) : $ this ->timezone ;
1087
1087
$ testTime = new DateTime ($ testTime , $ timezone );
1088
- } elseif ($ testTime instanceof self ) {
1088
+ } elseif ($ testTime instanceof static ) {
1089
1089
$ testTime = $ testTime ->toDateTime ();
1090
1090
}
1091
1091
@@ -1116,7 +1116,7 @@ public function difference($testTime, ?string $timezone = null)
1116
1116
*/
1117
1117
public function getUTCObject ($ time , ?string $ timezone = null )
1118
1118
{
1119
- if ($ time instanceof self ) {
1119
+ if ($ time instanceof static ) {
1120
1120
$ time = $ time ->toDateTime ();
1121
1121
} elseif (is_string ($ time )) {
1122
1122
$ timezone = $ timezone ?: $ this ->timezone ;
0 commit comments