diff --git a/src/Models/Attributes/Timestamp.php b/src/Models/Attributes/Timestamp.php index 60eaa139..4046eb71 100644 --- a/src/Models/Attributes/Timestamp.php +++ b/src/Models/Attributes/Timestamp.php @@ -190,7 +190,7 @@ protected function convertWindowsIntegerTimeToDateTime(string|int|null $value = } return (new DateTime)->setTimestamp( - round($value / 10000000) - 11644473600 + (int) ($value / 10000000) - 11644473600 ); } diff --git a/tests/Unit/Models/Attributes/TimestampTest.php b/tests/Unit/Models/Attributes/TimestampTest.php index 8224bab8..c852437a 100644 --- a/tests/Unit/Models/Attributes/TimestampTest.php +++ b/tests/Unit/Models/Attributes/TimestampTest.php @@ -146,4 +146,17 @@ public function test_windows_int_type_properly_handles_minimum() $this->assertSame($min, $timestamp->toDateTime($min)); $this->assertSame($min, $timestamp->toDateTime((string) $min)); } + + public function test_windows_int_type_rounds_correctly() + { + $timestamp = new Timestamp('windows-int'); + + foreach (['133692539995000000', '133692539999500000'] as $windowsIntegerTime) { + $dateTime = $timestamp->toDateTime($windowsIntegerTime); + + $expectedUnixTimestamp = (int) ($windowsIntegerTime / 10000000) - 11644473600; + + $this->assertEquals($expectedUnixTimestamp, $dateTime->getTimestamp()); + } + } }