Skip to content

Commit 20dabde

Browse files
committed
normalizeRow: time columns resets date to 0001-01-01 (BC break)
1 parent f5062e5 commit 20dabde

3 files changed

Lines changed: 7 additions & 8 deletions

File tree

src/Database/Helpers.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,14 @@ public static function normalizeRow(array $row, ResultSet $resultSet): array
220220
} elseif ($type === IStructure::FIELD_BOOL) {
221221
$row[$key] = $value && $value !== 'f' && $value !== 'F';
222222

223-
} elseif (
224-
$type === IStructure::FIELD_DATETIME
225-
|| $type === IStructure::FIELD_DATE
226-
|| $type === IStructure::FIELD_TIME
227-
) {
223+
} elseif ($type === IStructure::FIELD_DATETIME || $type === IStructure::FIELD_DATE) {
228224
$row[$key] = str_starts_with($value, '0000-00')
229225
? null
230226
: new Nette\Utils\DateTime($value);
231227

228+
} elseif ($type === IStructure::FIELD_TIME) {
229+
$row[$key] = (new Nette\Utils\DateTime($value))->setDate(1, 1, 1);
230+
232231
} elseif ($type === IStructure::FIELD_TIME_INTERVAL) {
233232
preg_match('#^(-?)(\d+)\D(\d+)\D(\d+)(\.\d+)?$#D', $value, $m);
234233
$row[$key] = new \DateInterval("PT$m[2]H$m[3]M$m[4]S");

tests/Database/ResultSet.normalizeRow.postgre.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Assert::equal([
3030
'money' => 0.0,
3131
'bool' => true,
3232
'date' => new DateTime('2012-10-13'),
33-
'time' => new DateTime('10:10:10'),
33+
'time' => new DateTime('0001-01-01 10:10:10'),
3434
'timestamp' => new DateTime('2012-10-13 10:10:10'),
3535
'timestampZone' => new DateTime('2012-10-13 09:10:10+00'),
3636
'interval' => '1 year',

tests/Database/ResultSet.normalizeRow.sqlsrv.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Assert::equal([
4242
'smallint' => 1,
4343
'smallmoney' => 1.1,
4444
'text' => 'a',
45-
'time' => new DateTime('10:10:10'),
45+
'time' => new DateTime('0001-01-01 10:10:10'),
4646
'tinyint' => 1,
4747
'uniqueidentifier' => '678E9994-A048-11E2-9030-003048D30C14',
4848
'varbinary' => "\x01",
@@ -75,7 +75,7 @@ Assert::equal([
7575
'smallint' => 0,
7676
'smallmoney' => 0.5,
7777
'text' => '',
78-
'time' => new DateTime('00:00:00'),
78+
'time' => new DateTime('0001-01-01 00:00:00'),
7979
'tinyint' => 0,
8080
'uniqueidentifier' => '00000000-0000-0000-0000-000000000000',
8181
'varbinary' => "\x00",

0 commit comments

Comments
 (0)