Skip to content

Commit

Permalink
Support for microseconds (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
hubipe authored and dg committed Jun 9, 2017
1 parent 822ba09 commit e51d92f
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Dibi/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getTimestamp()

public function __toString()
{
return $this->format('Y-m-d H:i:s');
return $this->format('Y-m-d H:i:s.u');
}


Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/FirebirdDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public function escapeDateTime($value)
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
$value = new Dibi\DateTime($value);
}
return $value->format("'Y-m-d H:i:s'");
return $value->format("'Y-m-d H:i:s.u'");
}


Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/MsSqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public function escapeDateTime($value)
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
$value = new Dibi\DateTime($value);
}
return $value->format("'Y-m-d H:i:s'");
return $value->format("'Y-m-d H:i:s.u'");
}


Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/MySqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public function escapeDateTime($value)
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
$value = new Dibi\DateTime($value);
}
return $value->format("'Y-m-d H:i:s'");
return $value->format("'Y-m-d H:i:s.u'");
}


Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/MySqliDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public function escapeDateTime($value)
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
$value = new Dibi\DateTime($value);
}
return $value->format("'Y-m-d H:i:s'");
return $value->format("'Y-m-d H:i:s.u'");
}


Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/OdbcDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public function escapeDateTime($value)
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
$value = new Dibi\DateTime($value);
}
return $value->format("#m/d/Y H:i:s#");
return $value->format("#m/d/Y H:i:s.u#");
}


Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/PdoDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public function escapeDateTime($value)
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
$value = new Dibi\DateTime($value);
}
return $value->format($this->driverName === 'odbc' ? "#m/d/Y H:i:s#" : "'Y-m-d H:i:s'");
return $value->format($this->driverName === 'odbc' ? "#m/d/Y H:i:s.u#" : "'Y-m-d H:i:s.u'");
}


Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/PostgreDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public function escapeDateTime($value)
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
$value = new Dibi\DateTime($value);
}
return $value->format("'Y-m-d H:i:s'");
return $value->format("'Y-m-d H:i:s.u'");
}


Expand Down
2 changes: 1 addition & 1 deletion src/Dibi/Drivers/SqlsrvDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public function escapeDateTime($value)
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
$value = new Dibi\DateTime($value);
}
return $value->format("'Y-m-d H:i:s'");
return $value->format("'Y-m-d H:i:s.u'");
}


Expand Down
7 changes: 4 additions & 3 deletions tests/dibi/Translator.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use Dibi\DateTime;

require __DIR__ . '/bootstrap.php';

$conn = new Dibi\Connection($config + ['formatDateTime' => "'Y-m-d H:i:s'", 'formatDate' => "'Y-m-d'"]);
$conn = new Dibi\Connection($config + ['formatDateTime' => "'Y-m-d H:i:s.u'", 'formatDate' => "'Y-m-d'"]);


// dibi detects INSERT or REPLACE command & booleans
Expand Down Expand Up @@ -178,8 +178,8 @@ if ($config['system'] === 'odbc') {

Assert::same(
reformat([
'odbc' => 'INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9]) VALUES (#09/26/1212 00:00:00#, #12/31/1969 22:13:20#, #09/26/1212#, #09/26/1212 00:00:00#, #12/31/1969#, #12/31/1969 22:13:20#, #09/26/1212 00:00:00#, #09/26/1212#, #09/26/1212 00:00:00#, NULL, NULL)',
"INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9]) VALUES ('1212-09-26 00:00:00', '1969-12-31 22:13:20', '1212-09-26', '1212-09-26 00:00:00', '1969-12-31', '1969-12-31 22:13:20', '1212-09-26 00:00:00', '1212-09-26', '1212-09-26 00:00:00', NULL, NULL)",
'odbc' => 'INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9], [c1]) VALUES (#09/26/1212 00:00:00.000000#, #12/31/1969 22:13:20.000000#, #09/26/1212#, #09/26/1212 00:00:00.000000#, #12/31/1969#, #12/31/1969 22:13:20.000000#, #09/26/1212 00:00:00.000000#, #09/26/1212#, #09/26/1212 00:00:00.000000#, NULL, NULL, #09/26/1212 16:51:34.012400#)',
"INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9], [c1]) VALUES ('1212-09-26 00:00:00.000000', '1969-12-31 22:13:20.000000', '1212-09-26', '1212-09-26 00:00:00.000000', '1969-12-31', '1969-12-31 22:13:20.000000', '1212-09-26 00:00:00.000000', '1212-09-26', '1212-09-26 00:00:00.000000', NULL, NULL, '1212-09-26 16:51:34.012400')",
]),
$conn->translate('INSERT INTO test', [
'a2' => new DateTime('1212-09-26'),
Expand All @@ -193,6 +193,7 @@ Assert::same(
'b7%t' => new DateTime('1212-09-26'),
'b8%d' => NULL,
'b9%t' => NULL,
'c1%t' => new DateTime('1212-09-26 16:51:34.0124'),
]));

Assert::exception(function () use ($conn) {
Expand Down

0 comments on commit e51d92f

Please sign in to comment.