Skip to content

Commit

Permalink
Give an option to set a date at midnight
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe committed Jul 9, 2024
1 parent 48b3708 commit 927fe9d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Casts/DateTimeInterfaceCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public function __construct(
protected null|string|array $format = null,
protected ?string $type = null,
protected ?string $setTimeZone = null,
protected ?string $timeZone = null
protected ?string $timeZone = null,
protected ?bool $setMidnight = false
) {
}

Expand Down Expand Up @@ -54,7 +55,12 @@ protected function castValue(
$this->setTimeZone ??= config('data.date_timezone');

if ($this->setTimeZone) {
return $datetime->setTimezone(new DateTimeZone($this->setTimeZone));
$datetime = $datetime->setTimezone(new DateTimeZone($this->setTimeZone));
}

//Force the time to 00:00:00.000
if ($this->setMidnight) {
$datetime = $datetime->setTime(0, 0);
}

return $datetime;
Expand Down

0 comments on commit 927fe9d

Please sign in to comment.