'YYYY-MM-dd HH:mm:ss'
);
function __construct($name, $title = null, $value = ""){
$this->dateField = new DateField($name . '[date]', false);
$this->timeField = new TimeField($name . '[time]', false);
parent::__construct($name, $title, $value);
}
function setForm($form) {
parent::setForm($form);
$this->dateField->setForm($form);
$this->timeField->setForm($form);
}
function Field() {
return $this->dateField->Field() . $this->timeField->Field();
}
/**
* Sets the internal value to ISO date format.
*
* @param string|array $val String expects an ISO date format. Array notation with 'date' and 'time'
* keys can contain localized strings. If the 'dmyfields' option is used for {@link DateField},
* the 'date' value may contain array notation was well (see {@link DateField->setValue()}).
*/
function setValue($val) {
if(empty($val)) {
$this->dateField->setValue(null);
$this->timeField->setValue(null);
} else {
// String setting is only possible from the database, so we don't allow anything but ISO format
if(is_string($val) && Zend_Date::isDate($val, $this->getConfig('datavalueformat'), $this->locale)) {
// split up in date and time string values.
$valueObj = new Zend_Date($val, $this->getConfig('datavalueformat'), $this->locale);
// set date either as array, or as string
if($this->dateField->getConfig('dmyfields')) {
$this->dateField->setValue($valueObj->toArray());
} else {
$this->dateField->setValue($valueObj->get($this->dateField->getConfig('dateformat')));
}
// set time
$this->timeField->setValue($valueObj->get($this->timeField->getConfig('timeformat')));
}
// Setting from form submission
elseif(is_array($val) && array_key_exists('date', $val) && array_key_exists('time', $val)) {
$this->dateField->setValue($val['date']);
$this->timeField->setValue($val['time']);
} else {
$this->dateField->setValue($val);
$this->timeField->setValue($val);
}
}
}
function dataValue() {
$valDate = $this->dateField->dataValue();
$valTime = $this->timeField->dataValue();
if($valDate && $valTime) {
return $valDate . ' ' . $valTime;
} else {
// TODO
return null;
}
}
/**
* @return DateField
*/
function getDateField() {
return $this->dateField;
}
/**
* @return TimeField
*/
function getTimeField() {
return $this->timeField;
}
function setLocale($locale) {
$this->dateField->setLocale($locale);
$this->timeField->setLocale($locale);
}
function getLocale() {
return $this->dateField->getLocale();
}
/**
* Note: Use {@link getDateField()} and {@link getTimeField()}
* to set field-specific config options.
*
* @param string $name
* @param mixed $val
*/
function setConfig($name, $val) {
$this->config[$name] = $val;
}
/**
* Note: Use {@link getDateField()} and {@link getTimeField()}
* to get field-specific config options.
*
* @param String $name
* @return mixed
*/
function getConfig($name) {
return $this->config[$name];
}
function validate($validator) {
$dateValid = $this->dateField->validate($validator);
$timeValid = $this->timeField->validate($validator);
return ($dateValid && $timeValid);
}
function jsValidation() {
return $this->dateField->jsValidation() . $this->timeField->jsValidation();
}
function performReadonlyTransformation() {
$field = new DatetimeField_Readonly($this->name, $this->title, $this->dataValue());
$field->setForm($this->form);
return $field;
}
}
/**
* The readonly class for our {@link DatetimeField}.
*
* @package forms
* @subpackage fields-datetime
*/
class DatetimeField_Readonly extends DatetimeField {
protected $readonly = true;
function Field() {
$valDate = $this->dateField->dataValue();
$valTime = $this->timeField->dataValue();
if($valDate && $valTime) {
$format = $this->dateField->getConfig('dateformat') . ' ' . $this->timeField->getConfig('timeformat');
$valueObj = new Zend_Date(
$valDate . ' ' . $valTime,
$this->getConfig('datavalueformat'),
$this->dateField->getLocale()
);
$val = $valueObj->toString($format);
} else {
// TODO Localization
$val = '(not set)';
}
return "id() . "\">$val";
}
function jsValidation() {
return null;
}
function validate($validator) {
return true;
}
}
?>