Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Behavior/MillisecondTimestamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
return null;
}

$datetime = DateTime::createFromFormat('U.u', sprintf('%F', $value / 1000.0));

Check failure on line 19 in src/Behavior/MillisecondTimestamp.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.4) / PHPStan 8.4

Binary operation "/" between mixed and 1000.0 results in an error.

Check failure on line 19 in src/Behavior/MillisecondTimestamp.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.3) / PHPStan 8.3

Binary operation "/" between mixed and 1000.0 results in an error.

Check failure on line 19 in src/Behavior/MillisecondTimestamp.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.5) / PHPStan 8.5

Binary operation "/" between mixed and 1000.0 results in an error.

Check failure on line 19 in src/Behavior/MillisecondTimestamp.php

View workflow job for this annotation

GitHub Actions / PHP / Static analysis (8.2) / PHPStan 8.2

Binary operation "/" between mixed and 1000.0 results in an error.
$datetime->setTimezone(new DateTimeZone(date_default_timezone_get()));

return $datetime;
Expand All @@ -24,6 +24,10 @@

public function toDb($value, $key, $context)
{
if ($value === null) {
return null;
}

if (is_numeric($value)) {
return (int) ($value * 1000.0);
}
Expand Down
5 changes: 5 additions & 0 deletions tests/MillisecondTimestampBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public function testFromDbReturnsNullWhenNullIsPassed()
$this->assertNull((new MillisecondTimestamp([]))->fromDb(null, 'key', null));
}

public function testToDbReturnsNullWhenNullIsPassed()
{
$this->assertNull((new MillisecondTimestamp([]))->toDb(null, 'key', null));
}

public function testToDbReturnsUtcTimestampWithNonUtcInput()
{
$sometime = DateTime::createFromFormat(
Expand Down
Loading