Skip to content

Commit

Permalink
normalizeRow: converts zero-date 0000-00-00 to NULL (BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 5, 2023
1 parent 51afaa5 commit c09894e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/Database/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ public static function normalizeRow(array $row, ResultSet $resultSet): array
|| $type === IStructure::FIELD_DATE
|| $type === IStructure::FIELD_TIME
) {
$row[$key] = new Nette\Utils\DateTime($value);
$row[$key] = str_starts_with((string) $value, '0000-00')
? null
: new Nette\Utils\DateTime($value);

} elseif ($type === IStructure::FIELD_TIME_INTERVAL) {
preg_match('#^(-?)(\d+)\D(\d+)\D(\d+)(\.\d+)?$#D', $value, $m);
Expand Down
6 changes: 3 additions & 3 deletions tests/Database/ResultSet.normalizeRow.mysql.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ Assert::equal([
'decimal2' => 0.5,
'float' => 0.5,
'double' => 0.5,
'date' => new DateTime('0000-00-00 00:00:00'),
'date' => null,
'time' => new DateInterval('P0D'),
'datetime' => new DateTime('0000-00-00 00:00:00'),
'timestamp' => new DateTime('0000-00-00 00:00:00'),
'datetime' => null,
'timestamp' => null,
'year' => 2000,
'char' => '',
'varchar' => '',
Expand Down

0 comments on commit c09894e

Please sign in to comment.