Skip to content

Commit

Permalink
drivers: added assert for DateTime & DateTimeImmutable, since DateTim…
Browse files Browse the repository at this point in the history
…eInterface does not have all shared methods
  • Loading branch information
hrach committed Jan 1, 2017
1 parent 5a6c5b2 commit a607482
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Drivers/Mysqli/MysqliDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public function convertIdentifierToSql(string $value): string

public function convertDatetimeToSql(\DateTimeInterface $value): string
{
assert($value instanceof \DateTime || $value instanceof \DateTimeImmutable);
if ($value->getTimezone()->getName() !== $this->connectionTz->getName()) {
if ($value instanceof \DateTimeImmutable) {
$value = $value->setTimezone($this->connectionTz);
Expand All @@ -253,12 +254,13 @@ public function convertDatetimeToSql(\DateTimeInterface $value): string

public function convertDatetimeSimpleToSql(\DateTimeInterface $value): string
{
assert($value instanceof \DateTime || $value instanceof \DateTimeImmutable);
if ($value->getTimezone()->getName() !== $this->simpleStorageTz->getName()) {
if ($value instanceof \DateTimeImmutable) {
$value = $value->setTimezone($this->simpleStorageTz);
} else {
$value = clone $value;
$value->setTimeZone($this->simpleStorageTz);
$value->setTimezone($this->simpleStorageTz);
}
}
return "'" . $value->format('Y-m-d H:i:s') . "'";
Expand Down
2 changes: 2 additions & 0 deletions src/Drivers/Pgsql/PgsqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public function convertIdentifierToSql(string $value): string

public function convertDateTimeToSql(\DateTimeInterface $value): string
{
assert($value instanceof \DateTime || $value instanceof \DateTimeImmutable);
if ($value->getTimezone()->getName() !== $this->connectionTz->getName()) {
if ($value instanceof \DateTimeImmutable) {
$value = $value->setTimezone($this->connectionTz);
Expand All @@ -253,6 +254,7 @@ public function convertDateTimeToSql(\DateTimeInterface $value): string

public function convertDateTimeSimpleToSql(\DateTimeInterface $value): string
{
assert($value instanceof \DateTime || $value instanceof \DateTimeImmutable);
if ($value->getTimezone()->getName() !== $this->simpleStorageTz->getName()) {
if ($value instanceof \DateTimeImmutable) {
$value = $value->setTimezone($this->simpleStorageTz);
Expand Down

0 comments on commit a607482

Please sign in to comment.