Add datetime picker for start date
This commit is contained in:
@@ -85,8 +85,7 @@ class DateParser extends Base
|
||||
*/
|
||||
public function getTimestamp($value)
|
||||
{
|
||||
foreach ($this->getDateFormats() as $format) {
|
||||
|
||||
foreach ($this->getAllFormats() as $format) {
|
||||
$timestamp = $this->getValidDate($value, $format);
|
||||
|
||||
if ($timestamp !== 0) {
|
||||
@@ -97,6 +96,25 @@ class DateParser extends Base
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all combinations of date/time formats
|
||||
*
|
||||
* @access public
|
||||
* @return []string
|
||||
*/
|
||||
public function getAllFormats()
|
||||
{
|
||||
$formats = array();
|
||||
|
||||
foreach ($this->getDateFormats() as $date) {
|
||||
foreach ($this->getTimeFormats() as $time) {
|
||||
$formats[] = $date.' '.$time;
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge($formats, $this->getDateFormats());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of supported date formats (for the parser)
|
||||
*
|
||||
@@ -112,6 +130,21 @@ class DateParser extends Base
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of supported time formats (for the parser)
|
||||
*
|
||||
* @access public
|
||||
* @return string[]
|
||||
*/
|
||||
public function getTimeFormats()
|
||||
{
|
||||
return array(
|
||||
'H:i',
|
||||
'g:i A',
|
||||
'g:iA',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of available date formats (for the config page)
|
||||
*
|
||||
@@ -143,7 +176,7 @@ class DateParser extends Base
|
||||
* Get a timetstamp from an ISO date format
|
||||
*
|
||||
* @access public
|
||||
* @param string $date Date format
|
||||
* @param string $date
|
||||
* @return integer
|
||||
*/
|
||||
public function getTimestampFromIsoFormat($date)
|
||||
@@ -166,7 +199,6 @@ class DateParser extends Base
|
||||
}
|
||||
|
||||
foreach ($fields as $field) {
|
||||
|
||||
if (! empty($values[$field])) {
|
||||
$values[$field] = date($format, $values[$field]);
|
||||
}
|
||||
@@ -180,15 +212,16 @@ class DateParser extends Base
|
||||
* Convert date (form input data)
|
||||
*
|
||||
* @access public
|
||||
* @param array $values Database values
|
||||
* @param string[] $fields Date fields
|
||||
* @param array $values Database values
|
||||
* @param string[] $fields Date fields
|
||||
* @param boolean $keep_time Keep time or not
|
||||
*/
|
||||
public function convert(array &$values, array $fields)
|
||||
public function convert(array &$values, array $fields, $keep_time = false)
|
||||
{
|
||||
foreach ($fields as $field) {
|
||||
|
||||
if (! empty($values[$field]) && ! is_numeric($values[$field])) {
|
||||
$values[$field] = $this->removeTimeFromTimestamp($this->getTimestamp($values[$field]));
|
||||
$timestamp = $this->getTimestamp($values[$field]);
|
||||
$values[$field] = $keep_time ? $timestamp : $this->removeTimeFromTimestamp($timestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,8 @@ class TaskCreation extends Base
|
||||
*/
|
||||
public function prepare(array &$values)
|
||||
{
|
||||
$this->dateParser->convert($values, array('date_due', 'date_started'));
|
||||
$this->dateParser->convert($values, array('date_due'));
|
||||
$this->dateParser->convert($values, array('date_started'), true);
|
||||
$this->removeFields($values, array('another_task'));
|
||||
$this->resetFields($values, array('owner_id', 'swimlane_id', 'date_due', 'score', 'category_id', 'time_estimated'));
|
||||
|
||||
|
||||
@@ -83,7 +83,8 @@ class TaskModification extends Base
|
||||
*/
|
||||
public function prepare(array &$values)
|
||||
{
|
||||
$this->dateParser->convert($values, array('date_due', 'date_started'));
|
||||
$this->dateParser->convert($values, array('date_due'));
|
||||
$this->dateParser->convert($values, array('date_started'), true);
|
||||
$this->removeFields($values, array('another_task', 'id'));
|
||||
$this->resetFields($values, array('date_due', 'date_started', 'score', 'category_id', 'time_estimated', 'time_spent'));
|
||||
$this->convertIntegerFields($values, array('is_active', 'recurrence_status', 'recurrence_trigger', 'recurrence_factor', 'recurrence_timeframe', 'recurrence_basedate'));
|
||||
|
||||
@@ -39,7 +39,7 @@ class TaskValidator extends Base
|
||||
new Validators\Integer('recurrence_status', t('This value must be an integer')),
|
||||
new Validators\MaxLength('title', t('The maximum length is %d characters', 200), 200),
|
||||
new Validators\Date('date_due', t('Invalid date'), $this->dateParser->getDateFormats()),
|
||||
new Validators\Date('date_started', t('Invalid date'), $this->dateParser->getDateFormats()),
|
||||
new Validators\Date('date_started', t('Invalid date'), $this->dateParser->getAllFormats()),
|
||||
new Validators\Numeric('time_spent', t('This value must be numeric')),
|
||||
new Validators\Numeric('time_estimated', t('This value must be numeric')),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user