mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #272 from halkyon/date_fixes
DateField::setValue() with dmyfields sets erroneous date in valueObj
This commit is contained in:
commit
f81ad47239
@ -196,8 +196,13 @@ class DateField extends TextField {
|
||||
// Setting in correct locale
|
||||
if(is_array($val) && $this->validateArrayValue($val)) {
|
||||
// set() gets confused with custom date formats when using array notation
|
||||
if(!(empty($val['day']) || empty($val['month']) || empty($val['year']))) {
|
||||
$this->valueObj = new Zend_Date($val, null, $this->locale);
|
||||
$this->value = $this->valueObj->toArray();
|
||||
} else {
|
||||
$this->value = $val;
|
||||
$this->valueObj = null;
|
||||
}
|
||||
}
|
||||
// load ISO date from database (usually through Form->loadDataForm())
|
||||
else if(!empty($val) && Zend_Date::isDate($val, $this->getConfig('datavalueformat'), $this->locale)) {
|
||||
|
@ -136,6 +136,17 @@ class DateFieldTest extends SapphireTest {
|
||||
// $this->assertFalse($f->validate(new RequiredFields()));
|
||||
}
|
||||
|
||||
function testValidateEmptyArrayValuesSetsNullForValueObject() {
|
||||
$f = new DateField('Date', 'Date');
|
||||
$f->setConfig('dmyfields', true);
|
||||
|
||||
$f->setValue(array('day' => '', 'month' => '', 'year' => ''));
|
||||
$this->assertNull($f->dataValue());
|
||||
|
||||
$f->setValue(array('day' => null, 'month' => null, 'year' => null));
|
||||
$this->assertNull($f->dataValue());
|
||||
}
|
||||
|
||||
function testValidateArrayValue() {
|
||||
$f = new DateField('Date', 'Date');
|
||||
$this->assertTrue($f->validateArrayValue(array('day' => 29, 'month' => 03, 'year' => 2003)));
|
||||
|
Loading…
Reference in New Issue
Block a user