Skip to content

Commit e7e6b88

Browse files
committed
DateTime::relativeToSeconds() checks for error
1 parent 534b599 commit e7e6b88

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/Utils/DateTime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function setTime(int $hour, int $minute, int $second = 0, int $microsecon
149149
*/
150150
public static function relativeToSeconds(string $relativeTime): int
151151
{
152-
return (new \DateTimeImmutable('1970-01-01 ' . $relativeTime, new \DateTimeZone('UTC')))
152+
return (new self('@0 ' . $relativeTime))
153153
->getTimestamp();
154154
}
155155

tests/Utils/DateTime.relativeToSeconds.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ test('relativeToSeconds throws on invalid', function () {
2828
Throwable::class,
2929
'%a?%Failed to parse time string %a%',
3030
);
31+
32+
Assert::error(
33+
fn() => DateTime::relativeToSeconds('1 minu'),
34+
E_USER_WARNING,
35+
);
3136
});

0 commit comments

Comments
 (0)