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:
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user