Skip to content

Commit 83b2de7

Browse files
authored
Merge pull request #781 from DirectoryTree/bug-779
Bug 779 - Rounding error when retrieving timestamp from Active Directory
2 parents d4d4fce + 8681746 commit 83b2de7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Models/Attributes/Timestamp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ protected function convertWindowsIntegerTimeToDateTime(string|int|null $value =
190190
}
191191

192192
return (new DateTime)->setTimestamp(
193-
round($value / 10000000) - 11644473600
193+
(int) ($value / 10000000) - 11644473600
194194
);
195195
}
196196

tests/Unit/Models/Attributes/TimestampTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,17 @@ public function test_windows_int_type_properly_handles_minimum()
146146
$this->assertSame($min, $timestamp->toDateTime($min));
147147
$this->assertSame($min, $timestamp->toDateTime((string) $min));
148148
}
149+
150+
public function test_windows_int_type_rounds_correctly()
151+
{
152+
$timestamp = new Timestamp('windows-int');
153+
154+
foreach (['133692539995000000', '133692539999500000'] as $windowsIntegerTime) {
155+
$dateTime = $timestamp->toDateTime($windowsIntegerTime);
156+
157+
$expectedUnixTimestamp = (int) ($windowsIntegerTime / 10000000) - 11644473600;
158+
159+
$this->assertEquals($expectedUnixTimestamp, $dateTime->getTimestamp());
160+
}
161+
}
149162
}

0 commit comments

Comments
 (0)