Skip to content

Commit be44d70

Browse files
committed
FIX failing queries on datetime fields set to 1970-01-01 00:00:00 v. int
1 parent 86b806a commit be44d70

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/Propel/Runtime/Util/PropelDateTime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public static function newInstance($value, ?DateTimeZone $timeZone = null, strin
116116
if ($value instanceof DateTimeInterface) {
117117
return $value;
118118
}
119-
if (!$value) {
119+
if ($value === false || $value === null || $value === '') {
120120
// '' is seen as NULL for temporal objects
121121
// because DateTime('') == DateTime('now') -- which is unexpected
122122
return null;

tests/Propel/Tests/Runtime/Util/PropelDateTimeTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ public function provideValidNewInstanceValues()
208208
'Y-m-d' => ['2011-08-10', '2011-08-10 00:00:00'],
209209
// 1312960848 : Wed, 10 Aug 2011 07:20:48 GMT
210210
'unix_timestamp' => ['1312960848', '2011-08-10 07:20:48'],
211+
'unix_timestamp_epoch' => ['0', '1970-01-01 00:00:00'],
211212
'Y-m-d H:is' => ['2011-08-10 10:22:15', '2011-08-10 10:22:15'],
212213
'Ymd' => ['20110810', '2011-08-10 00:00:00'],
213214
'Ymd2' => ['20110720', '2011-07-20 00:00:00'],
@@ -234,6 +235,7 @@ public function provideValidNewInstanceValuesGmt1()
234235
public function testIsTimestamp()
235236
{
236237
$this->assertEquals(false, TestPropelDateTime::isTimestamp('20110325'));
238+
$this->assertEquals(true, TestPropelDateTime::isTimestamp(0));
237239
$this->assertEquals(true, TestPropelDateTime::isTimestamp(1319580000));
238240
$this->assertEquals(true, TestPropelDateTime::isTimestamp('1319580000'));
239241
$this->assertEquals(false, TestPropelDateTime::isTimestamp('2011-07-20 00:00:00'));

0 commit comments

Comments
 (0)