Skip to content

Commit 5bb2651

Browse files
committed
fix: DatetimeCast::set() loses microseconds
1 parent 5d1ad1e commit 5bb2651

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

system/DataCaster/Cast/DatetimeCast.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ public static function set(
6262
self::invalidTypeValueError($value);
6363
}
6464

65-
return (string) $value;
65+
if (! $helper instanceof BaseConnection) {
66+
$message = 'The parameter $helper must be BaseConnection.';
67+
68+
throw new InvalidArgumentException($message);
69+
}
70+
71+
$format = match ($params[0] ?? '') {
72+
'' => $helper->dateFormat['datetime'],
73+
'ms' => $helper->dateFormat['datetime-ms'],
74+
'us' => $helper->dateFormat['datetime-us'],
75+
default => throw new InvalidArgumentException('Invalid parameter: ' . $params[0]),
76+
};
77+
78+
return $value->format($format);
6679
}
6780
}

0 commit comments

Comments
 (0)