Unverified Commit fab1b8ec authored by Michael Moravec's avatar Michael Moravec Committed by Marco Pivetta

Extract AbstractPlatform::DATE_INTERVAL_UNIT_* constants into DateIntervalUnit class

parent e6260dc6
# Upgrade to 2.7
## Doctrine\DBAL\Platforms\AbstractPlatform::DATE_INTERVAL_UNIT_* constants deprecated
``Doctrine\DBAL\Platforms\AbstractPlatform::DATE_INTERVAL_UNIT_*`` constants were moved into ``Doctrine\DBAL\Platforms\DateIntervalUnit`` class without the ``DATE_INTERVAL_UNIT_`` prefix.
## Doctrine\DBAL\Platforms\AbstractPlatform::TRIM_* constants deprecated
``Doctrine\DBAL\Platforms\AbstractPlatform::TRIM_*`` constants were moved into ``Doctrine\DBAL\Platforms\TrimMode`` class without the ``TRIM_`` prefix.
......
......@@ -70,44 +70,44 @@ abstract class AbstractPlatform
const CREATE_FOREIGNKEYS = 2;
/**
* @var string
* @deprecated Use DateIntervalUnit::INTERVAL_UNIT_SECOND.
*/
const DATE_INTERVAL_UNIT_SECOND = 'SECOND';
public const DATE_INTERVAL_UNIT_SECOND = DateIntervalUnit::SECOND;
/**
* @var string
* @deprecated Use DateIntervalUnit::MINUTE.
*/
const DATE_INTERVAL_UNIT_MINUTE = 'MINUTE';
public const DATE_INTERVAL_UNIT_MINUTE = DateIntervalUnit::MINUTE;
/**
* @var string
* @deprecated Use DateIntervalUnit::HOUR.
*/
const DATE_INTERVAL_UNIT_HOUR = 'HOUR';
public const DATE_INTERVAL_UNIT_HOUR = DateIntervalUnit::HOUR;
/**
* @var string
* @deprecated Use DateIntervalUnit::DAY.
*/
const DATE_INTERVAL_UNIT_DAY = 'DAY';
public const DATE_INTERVAL_UNIT_DAY = DateIntervalUnit::DAY;
/**
* @var string
* @deprecated Use DateIntervalUnit::WEEK.
*/
const DATE_INTERVAL_UNIT_WEEK = 'WEEK';
public const DATE_INTERVAL_UNIT_WEEK = DateIntervalUnit::WEEK;
/**
* @var string
* @deprecated Use DateIntervalUnit::MONTH.
*/
const DATE_INTERVAL_UNIT_MONTH = 'MONTH';
public const DATE_INTERVAL_UNIT_MONTH = DateIntervalUnit::MONTH;
/**
* @var string
* @deprecated Use DateIntervalUnit::QUARTER.
*/
const DATE_INTERVAL_UNIT_QUARTER = 'QUARTER';
public const DATE_INTERVAL_UNIT_QUARTER = DateIntervalUnit::QUARTER;
/**
* @var string
* @deprecated Use DateIntervalUnit::QUARTER.
*/
const DATE_INTERVAL_UNIT_YEAR = 'YEAR';
public const DATE_INTERVAL_UNIT_YEAR = DateIntervalUnit::YEAR;
/**
* @var int
......@@ -1057,7 +1057,7 @@ abstract class AbstractPlatform
*/
public function getDateAddSecondsExpression($date, $seconds)
{
return $this->getDateArithmeticIntervalExpression($date, '+', $seconds, self::DATE_INTERVAL_UNIT_SECOND);
return $this->getDateArithmeticIntervalExpression($date, '+', $seconds, DateIntervalUnit::SECOND);
}
/**
......@@ -1072,7 +1072,7 @@ abstract class AbstractPlatform
*/
public function getDateSubSecondsExpression($date, $seconds)
{
return $this->getDateArithmeticIntervalExpression($date, '-', $seconds, self::DATE_INTERVAL_UNIT_SECOND);
return $this->getDateArithmeticIntervalExpression($date, '-', $seconds, DateIntervalUnit::SECOND);
}
/**
......@@ -1087,7 +1087,7 @@ abstract class AbstractPlatform
*/
public function getDateAddMinutesExpression($date, $minutes)
{
return $this->getDateArithmeticIntervalExpression($date, '+', $minutes, self::DATE_INTERVAL_UNIT_MINUTE);
return $this->getDateArithmeticIntervalExpression($date, '+', $minutes, DateIntervalUnit::MINUTE);
}
/**
......@@ -1102,7 +1102,7 @@ abstract class AbstractPlatform
*/
public function getDateSubMinutesExpression($date, $minutes)
{
return $this->getDateArithmeticIntervalExpression($date, '-', $minutes, self::DATE_INTERVAL_UNIT_MINUTE);
return $this->getDateArithmeticIntervalExpression($date, '-', $minutes, DateIntervalUnit::MINUTE);
}
/**
......@@ -1117,7 +1117,7 @@ abstract class AbstractPlatform
*/
public function getDateAddHourExpression($date, $hours)
{
return $this->getDateArithmeticIntervalExpression($date, '+', $hours, self::DATE_INTERVAL_UNIT_HOUR);
return $this->getDateArithmeticIntervalExpression($date, '+', $hours, DateIntervalUnit::HOUR);
}
/**
......@@ -1132,7 +1132,7 @@ abstract class AbstractPlatform
*/
public function getDateSubHourExpression($date, $hours)
{
return $this->getDateArithmeticIntervalExpression($date, '-', $hours, self::DATE_INTERVAL_UNIT_HOUR);
return $this->getDateArithmeticIntervalExpression($date, '-', $hours, DateIntervalUnit::HOUR);
}
/**
......@@ -1147,7 +1147,7 @@ abstract class AbstractPlatform
*/
public function getDateAddDaysExpression($date, $days)
{
return $this->getDateArithmeticIntervalExpression($date, '+', $days, self::DATE_INTERVAL_UNIT_DAY);
return $this->getDateArithmeticIntervalExpression($date, '+', $days, DateIntervalUnit::DAY);
}
/**
......@@ -1162,7 +1162,7 @@ abstract class AbstractPlatform
*/
public function getDateSubDaysExpression($date, $days)
{
return $this->getDateArithmeticIntervalExpression($date, '-', $days, self::DATE_INTERVAL_UNIT_DAY);
return $this->getDateArithmeticIntervalExpression($date, '-', $days, DateIntervalUnit::DAY);
}
/**
......@@ -1177,7 +1177,7 @@ abstract class AbstractPlatform
*/
public function getDateAddWeeksExpression($date, $weeks)
{
return $this->getDateArithmeticIntervalExpression($date, '+', $weeks, self::DATE_INTERVAL_UNIT_WEEK);
return $this->getDateArithmeticIntervalExpression($date, '+', $weeks, DateIntervalUnit::WEEK);
}
/**
......@@ -1192,7 +1192,7 @@ abstract class AbstractPlatform
*/
public function getDateSubWeeksExpression($date, $weeks)
{
return $this->getDateArithmeticIntervalExpression($date, '-', $weeks, self::DATE_INTERVAL_UNIT_WEEK);
return $this->getDateArithmeticIntervalExpression($date, '-', $weeks, DateIntervalUnit::WEEK);
}
/**
......@@ -1207,7 +1207,7 @@ abstract class AbstractPlatform
*/
public function getDateAddMonthExpression($date, $months)
{
return $this->getDateArithmeticIntervalExpression($date, '+', $months, self::DATE_INTERVAL_UNIT_MONTH);
return $this->getDateArithmeticIntervalExpression($date, '+', $months, DateIntervalUnit::MONTH);
}
/**
......@@ -1222,7 +1222,7 @@ abstract class AbstractPlatform
*/
public function getDateSubMonthExpression($date, $months)
{
return $this->getDateArithmeticIntervalExpression($date, '-', $months, self::DATE_INTERVAL_UNIT_MONTH);
return $this->getDateArithmeticIntervalExpression($date, '-', $months, DateIntervalUnit::MONTH);
}
/**
......@@ -1237,7 +1237,7 @@ abstract class AbstractPlatform
*/
public function getDateAddQuartersExpression($date, $quarters)
{
return $this->getDateArithmeticIntervalExpression($date, '+', $quarters, self::DATE_INTERVAL_UNIT_QUARTER);
return $this->getDateArithmeticIntervalExpression($date, '+', $quarters, DateIntervalUnit::QUARTER);
}
/**
......@@ -1252,7 +1252,7 @@ abstract class AbstractPlatform
*/
public function getDateSubQuartersExpression($date, $quarters)
{
return $this->getDateArithmeticIntervalExpression($date, '-', $quarters, self::DATE_INTERVAL_UNIT_QUARTER);
return $this->getDateArithmeticIntervalExpression($date, '-', $quarters, DateIntervalUnit::QUARTER);
}
/**
......@@ -1267,7 +1267,7 @@ abstract class AbstractPlatform
*/
public function getDateAddYearsExpression($date, $years)
{
return $this->getDateArithmeticIntervalExpression($date, '+', $years, self::DATE_INTERVAL_UNIT_YEAR);
return $this->getDateArithmeticIntervalExpression($date, '+', $years, DateIntervalUnit::YEAR);
}
/**
......@@ -1282,7 +1282,7 @@ abstract class AbstractPlatform
*/
public function getDateSubYearsExpression($date, $years)
{
return $this->getDateArithmeticIntervalExpression($date, '-', $years, self::DATE_INTERVAL_UNIT_YEAR);
return $this->getDateArithmeticIntervalExpression($date, '-', $years, DateIntervalUnit::YEAR);
}
/**
......
......@@ -193,14 +193,14 @@ class DB2Platform extends AbstractPlatform
protected function getDateArithmeticIntervalExpression($date, $operator, $interval, $unit)
{
switch ($unit) {
case self::DATE_INTERVAL_UNIT_WEEK:
case DateIntervalUnit::WEEK:
$interval *= 7;
$unit = self::DATE_INTERVAL_UNIT_DAY;
$unit = DateIntervalUnit::DAY;
break;
case self::DATE_INTERVAL_UNIT_QUARTER:
case DateIntervalUnit::QUARTER:
$interval *= 3;
$unit = self::DATE_INTERVAL_UNIT_MONTH;
$unit = DateIntervalUnit::MONTH;
break;
}
......
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Platforms;
final class DateIntervalUnit
{
public const SECOND = 'SECOND';
public const MINUTE = 'MINUTE';
public const HOUR = 'HOUR';
public const DAY = 'DAY';
public const WEEK = 'WEEK';
public const MONTH = 'MONTH';
public const QUARTER = 'QUARTER';
public const YEAR = 'YEAR';
private function __construct()
{
}
}
......@@ -107,15 +107,15 @@ class OraclePlatform extends AbstractPlatform
protected function getDateArithmeticIntervalExpression($date, $operator, $interval, $unit)
{
switch ($unit) {
case self::DATE_INTERVAL_UNIT_MONTH:
case self::DATE_INTERVAL_UNIT_QUARTER:
case self::DATE_INTERVAL_UNIT_YEAR:
case DateIntervalUnit::MONTH:
case DateIntervalUnit::QUARTER:
case DateIntervalUnit::YEAR:
switch ($unit) {
case self::DATE_INTERVAL_UNIT_QUARTER:
case DateIntervalUnit::QUARTER:
$interval *= 3;
break;
case self::DATE_INTERVAL_UNIT_YEAR:
case DateIntervalUnit::YEAR:
$interval *= 12;
break;
}
......@@ -126,19 +126,19 @@ class OraclePlatform extends AbstractPlatform
$calculationClause = '';
switch ($unit) {
case self::DATE_INTERVAL_UNIT_SECOND:
case DateIntervalUnit::SECOND:
$calculationClause = '/24/60/60';
break;
case self::DATE_INTERVAL_UNIT_MINUTE:
case DateIntervalUnit::MINUTE:
$calculationClause = '/24/60';
break;
case self::DATE_INTERVAL_UNIT_HOUR:
case DateIntervalUnit::HOUR:
$calculationClause = '/24';
break;
case self::DATE_INTERVAL_UNIT_WEEK:
case DateIntervalUnit::WEEK:
$calculationClause = '*7';
break;
}
......
......@@ -129,9 +129,9 @@ class PostgreSqlPlatform extends AbstractPlatform
*/
protected function getDateArithmeticIntervalExpression($date, $operator, $interval, $unit)
{
if (self::DATE_INTERVAL_UNIT_QUARTER === $unit) {
if ($unit === DateIntervalUnit::QUARTER) {
$interval *= 3;
$unit = self::DATE_INTERVAL_UNIT_MONTH;
$unit = DateIntervalUnit::MONTH;
}
return "(" . $date ." " . $operator . " (" . $interval . " || ' " . $unit . "')::interval)";
......
......@@ -132,21 +132,21 @@ class SqlitePlatform extends AbstractPlatform
protected function getDateArithmeticIntervalExpression($date, $operator, $interval, $unit)
{
switch ($unit) {
case self::DATE_INTERVAL_UNIT_SECOND:
case self::DATE_INTERVAL_UNIT_MINUTE:
case self::DATE_INTERVAL_UNIT_HOUR:
case DateIntervalUnit::SECOND:
case DateIntervalUnit::MINUTE:
case DateIntervalUnit::HOUR:
return "DATETIME(" . $date . ",'" . $operator . $interval . " " . $unit . "')";
default:
switch ($unit) {
case self::DATE_INTERVAL_UNIT_WEEK:
case DateIntervalUnit::WEEK:
$interval *= 7;
$unit = self::DATE_INTERVAL_UNIT_DAY;
$unit = DateIntervalUnit::DAY;
break;
case self::DATE_INTERVAL_UNIT_QUARTER:
case DateIntervalUnit::QUARTER:
$interval *= 3;
$unit = self::DATE_INTERVAL_UNIT_MONTH;
$unit = DateIntervalUnit::MONTH;
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment