Skip to content

Commit 139e50f

Browse files
committed
DateTime::toString() returns microseconds (BC break)
1 parent 8ca4389 commit 139e50f

5 files changed

Lines changed: 13 additions & 13 deletions

File tree

src/Database/DateTime.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public function jsonSerialize(): string
4040

4141

4242
/**
43-
* Returns the date and time in the format 'Y-m-d H:i:s'.
43+
* Returns the date and time in the format 'Y-m-d H:i:s.u'.
4444
*/
4545
public function __toString(): string
4646
{
47-
return $this->format('Y-m-d H:i:s');
47+
return $this->format('Y-m-d H:i:s.u');
4848
}
4949
}

tests/Database/DateTime.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ require __DIR__ . '/../bootstrap.php';
1111
date_default_timezone_set('Europe/Prague');
1212

1313
// timestamp
14-
Assert::same('1978-01-23 11:40:00', (string) new DateTime(254_400_000));
14+
Assert::same('1978-01-23 11:40:00.000000', (string) new DateTime(254_400_000));
1515
Assert::same(254_400_000, (new DateTime(254_400_000))->getTimestamp());
1616

17-
Assert::same('2050-08-13 11:40:00', (string) new DateTime(254_400_0000));
17+
Assert::same('2050-08-13 11:40:00.000000', (string) new DateTime(254_400_0000));
1818
Assert::same(is_int(2_544_000_000) ? 2_544_000_000 : '2544000000', (new DateTime(2_544_000_000))->getTimestamp()); // 64 bit
1919

2020
// to string
21-
Assert::same('1978-01-23 11:40:00', (string) new DateTime('1978-01-23 11:40'));
21+
Assert::same('1978-01-23 11:40:00.000000', (string) new DateTime('1978-01-23 11:40'));
2222

2323
// JSON
2424
Assert::same('"1978-01-23T11:40:00+01:00"', json_encode(new DateTime('1978-01-23 11:40')));

tests/Database/ResultSet.fetchAssoc().phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ test('', function () use ($connection) {
5151
$pairs = $connection->query('UPDATE author SET born = ? WHERE id = 12', new DateTime('2002-02-02'));
5252
$pairs = $connection->query('SELECT * FROM author WHERE born IS NOT NULL ORDER BY born')->fetchAssoc('born=name');
5353
Assert::same([
54-
'2002-02-02 00:00:00' => 'David Grudl',
55-
'2002-02-20 00:00:00' => 'Jakub Vrana',
54+
'2002-02-02 00:00:00.000000' => 'David Grudl',
55+
'2002-02-20 00:00:00.000000' => 'Jakub Vrana',
5656
], $pairs);
5757
});

tests/Database/ResultSet.fetchPairs().phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ test('', function () use ($connection) {
7070
$pairs = $connection->query('UPDATE author SET born = ? WHERE id = 12', new DateTime('2002-02-02'));
7171
$pairs = $connection->query('SELECT * FROM author WHERE born IS NOT NULL ORDER BY born')->fetchPairs('born', 'name');
7272
Assert::same([
73-
'2002-02-02 00:00:00' => 'David Grudl',
74-
'2002-02-20 00:00:00' => 'Jakub Vrana',
73+
'2002-02-02 00:00:00.000000' => 'David Grudl',
74+
'2002-02-20 00:00:00.000000' => 'Jakub Vrana',
7575
], $pairs);
7676
});
7777

@@ -125,8 +125,8 @@ $pairs = $connection->query('UPDATE author SET born = ? WHERE id = 11', new Date
125125
$pairs = $connection->query('UPDATE author SET born = ? WHERE id = 12', new DateTime('2002-02-02'));
126126
$pairs = $connection->query('SELECT * FROM author WHERE born IS NOT NULL ORDER BY born')->fetchPairs('born', 'name');
127127
Assert::same([
128-
'2002-02-02 00:00:00' => 'David Grudl',
129-
'2002-02-20 00:00:00' => 'Jakub Vrana',
128+
'2002-02-02 00:00:00.000000' => 'David Grudl',
129+
'2002-02-20 00:00:00.000000' => 'Jakub Vrana',
130130
], $pairs);
131131

132132

tests/Database/Table/Selection.fetchPairs().phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ test('', function () use ($explorer) {
4141
$explorer->table('author')->get(12)->update(['born' => new DateTime('2002-02-02')]);
4242
$list = $explorer->table('author')->where('born IS NOT NULL')->order('born')->fetchPairs('born', 'name');
4343
Assert::same([
44-
'2002-02-02 00:00:00' => 'David Grudl',
45-
'2002-02-20 00:00:00' => 'Jakub Vrana',
44+
'2002-02-02 00:00:00.000000' => 'David Grudl',
45+
'2002-02-20 00:00:00.000000' => 'Jakub Vrana',
4646
], $list);
4747
});

0 commit comments

Comments
 (0)