matt bin Sat Apr 30 09:20:58 -0400 2011

Subject: date validation?

How do you guys validate that the date you recieve is in the right format, in your active record models?
with this format date ( 'Y-m-d H:i:s' )


Yoan B Sat Apr 30 13:03:34 -0400 2011

As date/datetime/timestamp are converted into DateTime testing must only be applied to the string ones. Try doing it with `validate` :

1 function validate() {
2     if ($this->foo_at && is_string($this->foo_at)) {
3         $foo_at = static::table()->conn->string_to_datetime($this->foo_at);
4         if ($foo_at === null) {
5             $this->errors->add('foo_at', 'is not a valid datetime');
6         }
7     }
8 }

Actually, I don't perform check on those much.

(1-1/1)