jonathangeiger / kohana-jelly

See the link below for the most up-to-date code
https://github.com/creatoro/jelly
MIT License
146 stars 34 forks source link

Jelly_Field_Timestamp's setter #183

Open alexgisby opened 13 years ago

alexgisby commented 13 years ago

Hi there,

Was having an issue with Jelly_Field_Timestamp's setter. If you give it the timestamp 1302372000 it tries to put 978267757 into the database. This is because there's a weird behaviour with PHP's strtotime where it interprets 1302372000 as a valid date and passes back a timestamp, not FALSE as you'd expect.

I've fixed this by swapping the order of the IF in Jelly_Field_Timestamp's setter;

public function set($value)
{
    if ($value === NULL OR ($this->null AND empty($value)))
    {
        return NULL;
    }

    // This is the other way around in master.
    if (is_numeric($value))
    {
        return (int) $value;
    }
    elseif (FALSE !== strtotime($value))
    {
        return strtotime($value);
    }

    return $value;
}

Which seems to work a treat.

Seemed too minor a change to bother forking, but sorry if that would have been easier.

Hope that's helpful to someone!