Skip to content

Commit f5062e5

Browse files
committed
normalizeRow: converts zero-date 0000-00-00 to NULL (BC break)
1 parent 70c9f60 commit f5062e5

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/Database/Helpers.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ public static function normalizeRow(array $row, ResultSet $resultSet): array
225225
|| $type === IStructure::FIELD_DATE
226226
|| $type === IStructure::FIELD_TIME
227227
) {
228-
$row[$key] = new Nette\Utils\DateTime($value);
228+
$row[$key] = str_starts_with($value, '0000-00')
229+
? null
230+
: new Nette\Utils\DateTime($value);
229231

230232
} elseif ($type === IStructure::FIELD_TIME_INTERVAL) {
231233
preg_match('#^(-?)(\d+)\D(\d+)\D(\d+)(\.\d+)?$#D', $value, $m);

tests/Database/ResultSet.normalizeRow.mysql.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ Assert::equal([
6464
'decimal2' => 0.5,
6565
'float' => 0.5,
6666
'double' => 0.5,
67-
'date' => new DateTime('0000-00-00 00:00:00'),
67+
'date' => null,
6868
'time' => new DateInterval('P0D'),
69-
'datetime' => new DateTime('0000-00-00 00:00:00'),
70-
'timestamp' => new DateTime('0000-00-00 00:00:00'),
69+
'datetime' => null,
70+
'timestamp' => null,
7171
'year' => 2000,
7272
'char' => '',
7373
'varchar' => '',

0 commit comments

Comments
 (0)