Skip to content

Commit

Permalink
fix: DatetimeCast::set() loses microseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jul 29, 2024
1 parent 5d1ad1e commit 5bb2651
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion system/DataCaster/Cast/DatetimeCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ public static function set(
self::invalidTypeValueError($value);
}

return (string) $value;
if (! $helper instanceof BaseConnection) {
$message = 'The parameter $helper must be BaseConnection.';

throw new InvalidArgumentException($message);
}

$format = match ($params[0] ?? '') {
'' => $helper->dateFormat['datetime'],
'ms' => $helper->dateFormat['datetime-ms'],
'us' => $helper->dateFormat['datetime-us'],
default => throw new InvalidArgumentException('Invalid parameter: ' . $params[0]),
};

return $value->format($format);
}
}

0 comments on commit 5bb2651

Please sign in to comment.