Skip to content

Commit 7f86cf0

Browse files
committed
implemented MySqliDriver::escapeDateInterval()
1 parent e2dc926 commit 7f86cf0

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/Dibi/Drivers/MySqliDriver.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,10 @@ public function escapeDateTime(\DateTimeInterface $value): string
304304

305305
public function escapeDateInterval(\DateInterval $value): string
306306
{
307-
throw new Dibi\NotImplementedException;
307+
if ($value->y || $value->m || $value->d) {
308+
throw new Dibi\NotSupportedException('Only time interval is supported.');
309+
}
310+
return $value->format('%r%H:%I:%S.%f');
308311
}
309312

310313

tests/dibi/Translator.DateInterval.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ $conn = new Dibi\Connection($config);
1010
$translator = new Dibi\Translator($conn);
1111

1212
switch ($config['system']) {
13+
case 'mysql':
14+
Assert::equal('10:20:30.0', $translator->formatValue(new DateInterval('PT10H20M30S'), null));
15+
Assert::equal('-1:00:00.0', $translator->formatValue(DateInterval::createFromDateString('-1 hour'), null));
16+
Assert::exception(function () use ($translator) {
17+
$translator->formatValue(new DateInterval('P2Y4DT6H8M'), null);
18+
}, Dibi\NotSupportedException::class, 'Only time interval is supported.');
19+
break;
20+
1321
default:
1422
Assert::exception(function () use ($translator) {
1523
$translator->formatValue(new DateInterval('PT10H20M30S'), null);

0 commit comments

Comments
 (0)