Skip to content

Commit

Permalink
added dibi::stripMicroseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 19, 2018
1 parent 1032432 commit 030554e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Dibi/dibi.php
Expand Up @@ -177,4 +177,14 @@ public static function dump($sql = null, bool $return = false): ?string
{
return Dibi\Helpers::dump($sql, $return);
}


/**
* Strips microseconds part.
*/
public static function stripMicroseconds(\DateTimeInterface $dt): \DateTimeInterface
{
$class = get_class($dt);
return new $class($dt->format('Y-m-d H:i:s'), $dt->getTimezone());
}
}
13 changes: 13 additions & 0 deletions tests/dibi/dibi.stripMicroseconds.phpt
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

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'));

0 comments on commit 030554e

Please sign in to comment.