Skip to content

Commit

Permalink
FIX failing queries on datetime fields set to 1970-01-01 00:00:00 v. int
Browse files Browse the repository at this point in the history
  • Loading branch information
hsegnitz committed Jun 28, 2024
1 parent b35918b commit 5c249e2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Propel/Runtime/Util/PropelDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static function newInstance($value, ?DateTimeZone $timeZone = null, strin
if ($value instanceof DateTimeInterface) {
return $value;
}
if (!$value) {
if ($value === false || $value === null || $value === '') {
// '' is seen as NULL for temporal objects
// because DateTime('') == DateTime('now') -- which is unexpected
return null;
Expand Down
2 changes: 2 additions & 0 deletions tests/Propel/Tests/Runtime/Util/PropelDateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public function provideValidNewInstanceValues()
'Y-m-d' => ['2011-08-10', '2011-08-10 00:00:00'],
// 1312960848 : Wed, 10 Aug 2011 07:20:48 GMT
'unix_timestamp' => ['1312960848', '2011-08-10 07:20:48'],
'unix_timestamp_epoch' => ['0', '1970-01-01 00:00:00'],
'Y-m-d H:is' => ['2011-08-10 10:22:15', '2011-08-10 10:22:15'],
'Ymd' => ['20110810', '2011-08-10 00:00:00'],
'Ymd2' => ['20110720', '2011-07-20 00:00:00'],
Expand All @@ -234,6 +235,7 @@ public function provideValidNewInstanceValuesGmt1()
public function testIsTimestamp()
{
$this->assertEquals(false, TestPropelDateTime::isTimestamp('20110325'));
$this->assertEquals(true, TestPropelDateTime::isTimestamp(0));
$this->assertEquals(true, TestPropelDateTime::isTimestamp(1319580000));
$this->assertEquals(true, TestPropelDateTime::isTimestamp('1319580000'));
$this->assertEquals(false, TestPropelDateTime::isTimestamp('2011-07-20 00:00:00'));
Expand Down

0 comments on commit 5c249e2

Please sign in to comment.