mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
household list of accompanying periods + upgrade DBAL version to 3.1
This commit is contained in:
@@ -15,17 +15,17 @@ use Doctrine\DBAL\Types\ConversionException;
|
||||
class NativeDateIntervalType extends DateIntervalType
|
||||
{
|
||||
const FORMAT = '%rP%YY%MM%DDT%HH%IM%SS';
|
||||
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return \Doctrine\DBAL\Types\Type::DATEINTERVAL;
|
||||
return \Doctrine\DBAL\Types\Types::DATEINTERVAL;
|
||||
}
|
||||
|
||||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
|
||||
{
|
||||
return 'INTERVAL';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -41,36 +41,36 @@ class NativeDateIntervalType extends DateIntervalType
|
||||
|
||||
throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'DateInterval']);
|
||||
}
|
||||
|
||||
|
||||
public function convertToPHPValue($value, AbstractPlatform $platform)
|
||||
{
|
||||
if ($value === null || $value instanceof \DateInterval) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$strings = explode(' ', $value);
|
||||
|
||||
|
||||
if (count($strings) === 0) {
|
||||
return null;
|
||||
}
|
||||
$intervalSpec = 'P';
|
||||
\reset($strings);
|
||||
|
||||
|
||||
do {
|
||||
$intervalSpec .= $this->convertEntry($strings);
|
||||
} while (next($strings) !== FALSE);
|
||||
|
||||
|
||||
return new \DateInterval($intervalSpec);
|
||||
} catch (\Exception $exception) {
|
||||
throw $this->createConversionException($value, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function convertEntry(&$strings)
|
||||
{
|
||||
$current = \current($strings);
|
||||
|
||||
|
||||
if (is_numeric($current)) {
|
||||
$next = \next($strings);
|
||||
switch($next) {
|
||||
@@ -79,7 +79,7 @@ class NativeDateIntervalType extends DateIntervalType
|
||||
$unit = 'Y';
|
||||
break;
|
||||
case 'mon':
|
||||
case 'mons':
|
||||
case 'mons':
|
||||
$unit = 'M';
|
||||
break;
|
||||
case 'day':
|
||||
@@ -89,20 +89,20 @@ class NativeDateIntervalType extends DateIntervalType
|
||||
default:
|
||||
throw $this->createConversionException(implode('', $strings));
|
||||
}
|
||||
|
||||
|
||||
return $current.$unit;
|
||||
|
||||
|
||||
} elseif (\preg_match('/([0-9]{2}\:[0-9]{2}:[0-9]{2})/', $current) === 1) {
|
||||
$tExploded = explode(':', $current);
|
||||
$intervalSpec = 'T';
|
||||
$intervalSpec.= $tExploded[0].'H';
|
||||
$intervalSpec.= $tExploded[1].'M';
|
||||
$intervalSpec.= $tExploded[2].'S';
|
||||
|
||||
|
||||
return $intervalSpec;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function createConversionException($value, $exception = null)
|
||||
{
|
||||
return ConversionException::conversionFailedFormat($value, $this->getName(), 'xx year xx mons xx days 01:02:03', $exception);
|
||||
|
Reference in New Issue
Block a user