Add datetime picker for start date

This commit is contained in:
Frederic Guillot
2015-07-07 19:15:53 -04:00
parent 5e7e03a866
commit 58297ca3b1
19 changed files with 140 additions and 46 deletions

View File

@@ -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);
}
}
}