Skip to content

Commit c08b8bd

Browse files
committed
Handle millisecond LDAP timestamps
1 parent d66344a commit c08b8bd

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/Models/Attributes/Timestamp.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,12 @@ public function toDateTime(mixed $value): Carbon|int|false
127127
*/
128128
protected function convertLdapTimeToDateTime(string $value): DateTime|false
129129
{
130-
return DateTime::createFromFormat(
131-
str_contains($value, 'Z') ? 'YmdHis\Z' : 'YmdHisT',
132-
$value
133-
);
130+
return DateTime::createFromFormat(match (true) {
131+
str_contains($value, '000Z') => 'YmdHis.000\Z',
132+
str_contains($value, '0Z') => 'YmdHis.0\Z',
133+
str_contains($value, 'Z') => 'YmdHis\Z',
134+
default => 'YmdHisT'
135+
}, $value);
134136
}
135137

136138
/**
@@ -148,11 +150,10 @@ protected function convertDateTimeToLdapTime(DateTime $date): string
148150
*/
149151
protected function convertWindowsTimeToDateTime(string $value): DateTime|false
150152
{
151-
return DateTime::createFromFormat(
152-
str_contains($value, '0Z') ? 'YmdHis.0\Z' : 'YmdHis.0T',
153-
$value,
154-
new DateTimeZone('UTC')
155-
);
153+
return DateTime::createFromFormat(match (true) {
154+
str_contains($value, '0Z') => 'YmdHis.0\Z',
155+
default => 'YmdHis.0T'
156+
}, $value, new DateTimeZone('UTC'));
156157
}
157158

158159
/**

0 commit comments

Comments
 (0)