1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-03 12:47:33 +02:00

implemented MySqliDriver::escapeDateInterval()

This commit is contained in:
David Grudl
2019-08-30 18:50:55 +02:00
parent 369768a62a
commit 0535d57e6b
2 changed files with 12 additions and 1 deletions

View File

@@ -304,7 +304,10 @@ class MySqliDriver implements Dibi\Driver
public function escapeDateInterval(\DateInterval $value): string
{
throw new Dibi\NotImplementedException;
if ($value->y || $value->m || $value->d) {
throw new Dibi\NotSupportedException('Only time interval is supported.');
}
return $value->format('%r%H:%I:%S.%f');
}

View File

@@ -10,6 +10,14 @@ $conn = new Dibi\Connection($config);
$translator = new Dibi\Translator($conn);
switch ($config['system']) {
case 'mysql':
Assert::equal('10:20:30.0', $translator->formatValue(new DateInterval('PT10H20M30S'), null));
Assert::equal('-1:00:00.0', $translator->formatValue(DateInterval::createFromDateString('-1 hour'), null));
Assert::exception(function () use ($translator) {
$translator->formatValue(new DateInterval('P2Y4DT6H8M'), null);
}, Dibi\NotSupportedException::class, 'Only time interval is supported.');
break;
default:
Assert::exception(function () use ($translator) {
$translator->formatValue(new DateInterval('PT10H20M30S'), null);