Permalink
Browse files

MINOR Making date/time order and separation configurable through Date…

…timeField->setConfig('datetimeorder')
  • Loading branch information...
1 parent c89bdbb commit aa60201cd1e74f69bbf482a9076674096d26f4ba @chillu chillu committed Sep 26, 2011
Showing with 11 additions and 4 deletions.
  1. +11 −4 forms/DatetimeField.php
View
@@ -22,6 +22,8 @@
* the time in PHP's default timezone (date_default_timezone_get()), its only a view setting.
* Note that the sub-fields ({@link getDateField()} and {@link getTimeField()})
* are not timezone aware, and will have their values set in local time, rather than server time.
+ * - "datetimeorder": An sprintf() template to determine in which order the date and time values will
+ * be combined. This is necessary as those separate formats are set in their invididual fields.
*
* @package sapphire
* @subpackage forms
@@ -44,6 +46,7 @@ class DatetimeField extends FormField {
protected $config = array(
'datavalueformat' => 'YYYY-MM-dd HH:mm:ss',
'usertimezone' => null,
+ 'datetimeorder' => '%s %s',
);
function __construct($name, $title = null, $value = ""){
@@ -126,7 +129,7 @@ function setValue($val) {
unset($userValueObj);
} else {
// Validation happens later, so set the raw string in case Zend_Date doesn't accept it
- $this->value = $val['date'] . ' ' . $val['time'];
+ $this->value = sprintf($this->getConfig('datetimeorder'), $val['date'], $val['time']);
}
if($userTz) date_default_timezone_set($dataTz);
@@ -159,7 +162,7 @@ function Value() {
$valTime = $this->timeField->Value();
if(!$valTime) $valTime = '00:00:00';
- return $valDate . ' ' . $valTime;
+ return sprintf($this->getConfig('datetimeorder'), $valDate, $valTime);
}
/**
@@ -245,9 +248,13 @@ function Field() {
$valDate = $this->dateField->dataValue();
$valTime = $this->timeField->dataValue();
if($valDate && $valTime) {
- $format = $this->dateField->getConfig('dateformat') . ' ' . $this->timeField->getConfig('timeformat');
+ $format = sprintf(
+ $this->getConfig('datetimeorder'),
+ $this->dateField->getConfig('dateformat'),
+ $this->dateField->getConfig('timeformat')
+ );
$valueObj = new Zend_Date(
- $valDate . ' ' . $valTime,
+ sprintf($this->getConfig('datetimeorder'), $valDate, $valTime),
$this->getConfig('datavalueformat'),
$this->dateField->getLocale()
);

0 comments on commit aa60201

Please sign in to comment.