$v->setOption('datetime_output', 'U'); $v->setOption('with_time', true); $t->is($v->clean(time()), time(), '->clean() output format can be change with the date_output option'); // required $v = new sfValidatorDate(); foreach (array(array('year' => '', 'month' => '', 'day' => ''), array('year' => null, 'month' => null, 'day' => null), '', null) as $input) { try { $v->clean($input); $t->fail('->clean() throws an exception if the date is empty and required is true'); } catch (sfValidatorError $e) { $t->pass('->clean() throws an exception if the date is empty and required is true'); } } // max and min options $t->diag('max and min options'); $v->setOption('min', strtotime('1 Jan 2005')); $v->setOption('max', strtotime('31 Dec 2007')); $t->is($v->clean('18 october 2005'), '2005-10-18', '->clean() can accept a max/min option'); try { $v->clean('18 october 2004'); $t->fail('->clean() throws an exception if the date is not within the range provided by the min/max options'); } catch (sfValidatorError $e) { $t->pass('->clean() throws an exception if the date is not within the range provided by the min/max options'); } try { $v->clean('18 october 2008'); $t->fail('->clean() throws an exception if the date is not within the range provided by the min/max options'); } catch (sfValidatorError $e) { $t->pass('->clean() throws an exception if the date is not within the range provided by the min/max options'); } // timezones
$v->setOption('datetime_output', 'U'); $v->setOption('with_time', true); $t->is($v->clean(time()), time(), '->clean() output format can be change with the date_output option'); // required $v = new sfValidatorDate(); foreach (array(array('year' => '', 'month' => '', 'day' => ''), array('year' => null, 'month' => null, 'day' => null), '', null) as $input) { try { $v->clean($input); $t->fail('->clean() throws an exception if the date is empty and required is true'); } catch (sfValidatorError $e) { $t->pass('->clean() throws an exception if the date is empty and required is true'); } } // max and min options $t->diag('max and min options'); $v->setOption('min', strtotime('1 Jan 2005')); $v->setOption('max', strtotime('31 Dec 2007')); $t->is($v->clean('18 october 2005'), '2005-10-18', '->clean() can accept a max/min option'); try { $v->clean('18 october 2004'); $t->fail('->clean() throws an exception if the date is not within the range provided by the min/max options'); } catch (sfValidatorError $e) { $t->pass('->clean() throws an exception if the date is not within the range provided by the min/max options'); } try { $v->clean('18 october 2008'); $t->fail('->clean() throws an exception if the date is not within the range provided by the min/max options'); } catch (sfValidatorError $e) { $t->pass('->clean() throws an exception if the date is not within the range provided by the min/max options'); } // max and min options out off timestamp range
$t->is($v->clean(time()), time(), '->clean() output format can be change with the date_output option'); $v->setOption('datetime_output', 'U'); $v->setOption('with_time', true); $t->is($v->clean(time()), time(), '->clean() output format can be change with the date_output option'); // required $v = new sfValidatorDate(); foreach (array(array('year' => '', 'month' => '', 'day' => ''), array('year' => null, 'month' => null, 'day' => null), '', null) as $input) { try { $v->clean($input); $t->fail('->clean() throws an exception if the date is empty and required is true'); } catch (sfValidatorError $e) { $t->pass('->clean() throws an exception if the date is empty and required is true'); } } // max and min options $t->diag('max and min options'); $v->setOption('min', strtotime('1 Jan 2005')); $v->setOption('max', strtotime('31 Dec 2007')); $t->is($v->clean('18 october 2005'), '2005-10-18', '->clean() can accept a max/min option'); try { $v->clean('18 october 2004'); $t->fail('->clean() throws an exception if the date is not within the range provided by the min/max options'); } catch (sfValidatorError $e) { $t->pass('->clean() throws an exception if the date is not within the range provided by the min/max options'); } try { $v->clean('18 october 2008'); $t->fail('->clean() throws an exception if the date is not within the range provided by the min/max options'); } catch (sfValidatorError $e) { $t->pass('->clean() throws an exception if the date is not within the range provided by the min/max options'); }