mirror of
https://github.com/dg/dibi.git
synced 2025-08-22 13:43:12 +02:00
added dibi::stripMicroseconds
This commit is contained in:
@@ -447,4 +447,16 @@ class dibi
|
|||||||
{
|
{
|
||||||
return Dibi\Helpers::dump($sql, $return);
|
return Dibi\Helpers::dump($sql, $return);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strips microseconds part.
|
||||||
|
* @param \DateTime|\DateTimeInterface
|
||||||
|
* @return \DateTime|\DateTimeInterface
|
||||||
|
*/
|
||||||
|
public static function stripMicroseconds($dt)
|
||||||
|
{
|
||||||
|
$class = get_class($dt);
|
||||||
|
return new $class($dt->format('Y-m-d H:i:s'), $dt->getTimezone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
11
tests/dibi/dibi.stripMicroseconds.phpt
Normal file
11
tests/dibi/dibi.stripMicroseconds.phpt
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Tester\Assert;
|
||||||
|
|
||||||
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
$dt = new DateTime('2018-04-18 13:40:09.123456');
|
||||||
|
|
||||||
|
$res = dibi::stripMicroseconds($dt);
|
||||||
|
Assert::same('2018-04-18 13:40:09.123456', $dt->format('Y-m-d H:i:s.u'));
|
||||||
|
Assert::same('2018-04-18 13:40:09.000000', $res->format('Y-m-d H:i:s.u'));
|
Reference in New Issue
Block a user