Skip to content

Commit

Permalink
normalizeRow: time columns resets date to 0001-01-01 (BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 3, 2023
1 parent 24fb4bc commit ef9d3fe
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Database/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,14 @@ public static function normalizeRow(array $row, ResultSet $resultSet): array
} elseif ($type === IStructure::FIELD_BOOL) {
$row[$key] = ((bool) $value) && $value !== 'f' && $value !== 'F';

} elseif (
$type === IStructure::FIELD_DATETIME
|| $type === IStructure::FIELD_DATE
|| $type === IStructure::FIELD_TIME
) {
} elseif ($type === IStructure::FIELD_DATETIME || $type === IStructure::FIELD_DATE) {
$row[$key] = str_starts_with((string) $value, '0000-00')
? null
: new Nette\Utils\DateTime($value);

} elseif ($type === IStructure::FIELD_TIME) {
$row[$key] = (new Nette\Utils\DateTime($value))->setDate(1, 1, 1);

} elseif ($type === IStructure::FIELD_TIME_INTERVAL) {
preg_match('#^(-?)(\d+)\D(\d+)\D(\d+)(\.\d+)?$#D', $value, $m);
$row[$key] = new \DateInterval("PT$m[2]H$m[3]M$m[4]S");
Expand Down

0 comments on commit ef9d3fe

Please sign in to comment.