propelorm / Propel2

Propel2 is an open-source high-performance Object-Relational Mapping (ORM) for modern PHP
http://propelorm.org/
MIT License
1.26k stars 399 forks source link

not nullable date and time fields cannot be set on exactly 1970-01-01 00:00:00 via (int)0 as that loosely evaluates to false in Propel\Runtime\Util\PropelDateTime #2010

Open hsegnitz opened 5 months ago

hsegnitz commented 5 months ago

The offending code:

    public static function newInstance($value, ?DateTimeZone $timeZone = null, string $dateTimeClass = 'DateTime')
    {
        if ($value instanceof DateTimeInterface) {
            return $value;
        }
        **if (!$value) {**
            // '' is seen as NULL for temporal objects
            // because DateTime('') == DateTime('now') -- which is unexpected
            return null;
        }

It should be rather

if ($value === false || $value === null || $value === '') {
    ....
}

PR incoming when I figure out running the tests locally ;)