Skip to content

Commit 80eaa89

Browse files
committed
PHP 8.4 compatibility
1 parent 99e30a9 commit 80eaa89

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

src/mako/chrono/TimeInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static function createFromDate(int $year, ?int $month = null, ?int $day =
7474
*
7575
* @return false|static
7676
*/
77-
public static function createFromTimestamp(int $timestamp, null|DateTimeZone|string $timeZone = null);
77+
public static function createFromTimestamp(float|int $timestamp, null|DateTimeZone|string $timeZone = null);
7878

7979
/**
8080
* Returns a new instance according to the specified DOS timestamp.

src/mako/chrono/traits/TimeTrait.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,7 @@ public static function createFromDOSTimestamp(int $timestamp, null|DateTimeZone|
9595
#[\ReturnTypeWillChange]
9696
public static function createFromFormat(string $format, string $time, null|DateTimeZone|string $timeZone = null)
9797
{
98-
if ($timeZone !== null) {
99-
if (($timeZone instanceof DateTimeZone) === false) {
100-
$timeZone = new DateTimeZone($timeZone);
101-
}
102-
103-
$dateTime = parent::createFromFormat($format, $time, $timeZone);
104-
}
105-
else {
106-
$dateTime = parent::createFromFormat($format, $time);
107-
}
108-
109-
return new static($dateTime->format('Y-m-d\TH:i:s'), $dateTime->getTimeZone());
98+
return new static(parent::createFromFormat($format, $time)->format('Y-m-d\TH:i:s.u'), $timeZone);
11099
}
111100

112101
/**

tests/unit/chrono/TimeImmutableTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ public function testCreateFromTimestamp(): void
165165

166166
//
167167

168+
$time = Time::createFromTimestamp(431093532.123);
169+
170+
$this->assertSame('431093532.123000', $time->format('U.u'));
171+
172+
//
173+
168174
$time = TimeImmutable::createFromTimestamp(431093532, 'Asia/Tokyo');
169175

170176
$this->assertSame('Asia/Tokyo', $time->getTimeZone()->getName());

tests/unit/chrono/TimeTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ public function testCreateFromFormat(): void
197197

198198
//
199199

200+
$time = Time::createFromTimestamp(431093532.123);
201+
202+
$this->assertSame('431093532.123000', $time->format('U.u'));
203+
204+
//
205+
200206
$time = Time::createFromFormat('Y-m-d H:i:s', '1983-08-30 13:37:33', 'Asia/Tokyo');
201207

202208
$this->assertSame('Asia/Tokyo', $time->getTimeZone()->getName());

0 commit comments

Comments
 (0)