mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Fix datetime field validation for the refactor
This commit is contained in:
parent
4a70662940
commit
9d7eef7cf3
@ -103,6 +103,21 @@ class DatetimeField extends TextField
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAttributes()
|
||||
{
|
||||
$attributes = parent::getAttributes();
|
||||
|
||||
$attributes['lang'] = i18n::convert_rfc1766($this->getLocale());
|
||||
|
||||
if ($this->getHTML5()) {
|
||||
$attributes['type'] = 'datetime-local';
|
||||
$attributes['min'] = $this->getMinDatetime();
|
||||
$attributes['max'] = $this->getMaxDatetime();
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
public function getSchemaDataDefaults()
|
||||
{
|
||||
$defaults = parent::getSchemaDataDefaults();
|
||||
@ -178,9 +193,9 @@ class DatetimeField extends TextField
|
||||
*/
|
||||
protected function getFormatter()
|
||||
{
|
||||
if ($this->getHTML5() && $this->datetimeFormat && $this->datetimeFormat !== DBDatetime::ISO_DATE) {
|
||||
if ($this->getHTML5() && $this->datetimeFormat && $this->datetimeFormat !== DBDatetime::ISO_DATETIME) {
|
||||
throw new \LogicException(
|
||||
'Please opt-out of HTML5 processing of ISO 8601 dates via setHTML5(false) if using setDateFormat()'
|
||||
'Please opt-out of HTML5 processing of ISO 8601 dates via setHTML5(false) if using setDatetimeFormat()'
|
||||
);
|
||||
}
|
||||
|
||||
@ -216,6 +231,43 @@ class DatetimeField extends TextField
|
||||
return $formatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get date format in CLDR standard format
|
||||
*
|
||||
* This can be set explicitly. If not, this will be generated from the current locale
|
||||
* with the current date length.
|
||||
*
|
||||
* @see http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Field-Symbol-Table
|
||||
*/
|
||||
public function getDateFormat()
|
||||
{
|
||||
if ($this->getHTML5()) {
|
||||
// Browsers expect ISO 8601 dates, localisation is handled on the client
|
||||
$this->setDatetimeFormat(DBDatetime::ISO_DATETIME);
|
||||
}
|
||||
|
||||
if ($this->datetimeFormat) {
|
||||
return $this->datetimeFormat;
|
||||
}
|
||||
|
||||
// Get from locale
|
||||
return $this->getFormatter()->getPattern();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set date format in CLDR standard format.
|
||||
* Only applicable with {@link setHTML5(false)}.
|
||||
*
|
||||
* @see http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Field-Symbol-Table
|
||||
* @param string $format
|
||||
* @return $this
|
||||
*/
|
||||
public function setDatetimeFormat($format)
|
||||
{
|
||||
$this->datetimeFormat = $format;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get formatter for converting to the target timezone, if timezone is set
|
||||
* Can return null if no timezone set
|
||||
@ -295,9 +347,6 @@ class DatetimeField extends TextField
|
||||
if ($timezoneFormatter) {
|
||||
$value = $timezoneFormatter->format($timestamp);
|
||||
}
|
||||
|
||||
// Set date / time components, which are unaware of their timezone
|
||||
list($date, $time) = explode(' ', $value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user