BUGFIX Respecting field specific locale settings in DatetimeField and DateField when validating and saving values (fixes #5931, thanks Tjofras) (from r110889)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112864 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-10-19 03:01:03 +00:00
parent 2d82ae6217
commit 31d442f5da
2 changed files with 7 additions and 6 deletions

View File

@ -151,8 +151,8 @@ class DateField extends TextField {
$this->value = $this->valueObj->toArray(); $this->value = $this->valueObj->toArray();
} }
// load ISO date from database (usually through Form->loadDataForm()) // load ISO date from database (usually through Form->loadDataForm())
else if(!empty($val) && Zend_Date::isDate($val, $this->getConfig('datavalueformat'))) { else if(!empty($val) && Zend_Date::isDate($val, $this->getConfig('datavalueformat'), $this->locale)) {
$this->valueObj = new Zend_Date($val, $this->getConfig('datavalueformat')); $this->valueObj = new Zend_Date($val, $this->getConfig('datavalueformat'), $this->locale);
$this->value = $this->valueObj->toArray(); $this->value = $this->valueObj->toArray();
} }
else { else {
@ -166,12 +166,13 @@ class DateField extends TextField {
// (en_NZ for 3rd of April, definetly not yyyy-MM-dd) // (en_NZ for 3rd of April, definetly not yyyy-MM-dd)
if(!empty($val) && Zend_Date::isDate($val, $this->getConfig('dateformat'), $this->locale)) { if(!empty($val) && Zend_Date::isDate($val, $this->getConfig('dateformat'), $this->locale)) {
$this->valueObj = new Zend_Date($val, $this->getConfig('dateformat'), $this->locale); $this->valueObj = new Zend_Date($val, $this->getConfig('dateformat'), $this->locale);
$this->value = $this->valueObj->get($this->getConfig('dateformat')); $this->value = $this->valueObj->get($this->getConfig('dateformat'), $this->locale);
} }
// load ISO date from database (usually through Form->loadDataForm()) // load ISO date from database (usually through Form->loadDataForm())
else if(!empty($val) && Zend_Date::isDate($val, $this->getConfig('datavalueformat'))) { else if(!empty($val) && Zend_Date::isDate($val, $this->getConfig('datavalueformat'))) {
$this->valueObj = new Zend_Date($val, $this->getConfig('datavalueformat')); $this->valueObj = new Zend_Date($val, $this->getConfig('datavalueformat'));
$this->value = $this->valueObj->get($this->getConfig('dateformat')); $this->value = $this->valueObj->get($this->getConfig('dateformat'), $this->locale);
} }
else { else {
$this->value = $val; $this->value = $val;

View File

@ -72,10 +72,10 @@ class DatetimeField extends FormField {
if($this->dateField->getConfig('dmyfields')) { if($this->dateField->getConfig('dmyfields')) {
$this->dateField->setValue($valueObj->toArray()); $this->dateField->setValue($valueObj->toArray());
} else { } else {
$this->dateField->setValue($valueObj->get($this->dateField->getConfig('dateformat'))); $this->dateField->setValue($valueObj->get($this->dateField->getConfig('dateformat'), $this->locale));
} }
// set time // set time
$this->timeField->setValue($valueObj->get($this->timeField->getConfig('timeformat'))); $this->timeField->setValue($valueObj->get($this->timeField->getConfig('timeformat'), $this->locale));
} }
// Setting from form submission // Setting from form submission
elseif(is_array($val) && array_key_exists('date', $val) && array_key_exists('time', $val)) { elseif(is_array($val) && array_key_exists('date', $val) && array_key_exists('time', $val)) {