Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1047031
D346.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Jun 29, 3:45 PM
Size
5 KB
Mime Type
text/x-diff
Expires
Mon, Jun 30, 3:45 PM (2 h, 51 m)
Engine
blob
Format
Raw Data
Handle
676763
Attached To
D346: INP-1746 Correct time parsing in date range filter
D346.diff
View Options
Index: branches/5.2.x/core/kernel/utility/formatters/date_formatter.php
===================================================================
--- branches/5.2.x/core/kernel/utility/formatters/date_formatter.php
+++ branches/5.2.x/core/kernel/utility/formatters/date_formatter.php
@@ -373,10 +373,11 @@
* @param mixed $value
* @param string $field_name
* @param kDBItem $object
+ * @param string $format Format.
* @return mixed
* @access public
*/
- public function Parse($value, $field_name, &$object)
+ public function Parse($value, $field_name, &$object, $format = null)
{
$options = $object->GetFieldOptions($field_name);
@@ -385,7 +386,10 @@
if($value == '') return NULL;
//return strtotime($value);
- $format = $options['input_format'];
+ if ( !isset($format) ) {
+ $format = $options['input_format'];
+ }
+
if ($dt_separator) $format = trim($format, $dt_separator);
$error_params = array(
Index: branches/5.2.x/core/units/helpers/search_helper.php
===================================================================
--- branches/5.2.x/core/units/helpers/search_helper.php
+++ branches/5.2.x/core/units/helpers/search_helper.php
@@ -602,18 +602,28 @@
$to = $this->processRangeField($object, $field_name, $field_options['submit_value'], 'to');
$day_seconds = 23 * 60 * 60 + 59 * 60 + 59;
- if ($from !== false && $to === false) {
- $from = strtotime(date('Y-m-d', $from) . ' 00:00:00', $from); // reset to morning
+
+ if ( is_numeric($from) && $to === null && date('H:i:s', $from) == '00:00:00' ) {
$to = $from + $day_seconds;
}
- elseif ($from === false && $to !== false) {
- $to = strtotime(date('Y-m-d', $to) . ' 23:59:59', $to); // reset to evening
- $from = $to - $day_seconds;
+ elseif ( $from === null && is_numeric($to) && date('H:i:s', $to) == '00:00:00' ) {
+ $from = $to;
+ $to += $day_seconds;
+ }
+
+ if ( is_numeric($from) && $to === null || $from === null && is_numeric($to) ) {
+ $from = $from === null ? $to : $from;
+ $to = $from;
}
- if ($from !== false && $to !== false) {
+ if ( is_numeric($from) && is_numeric($to) ) {
+ $from = strtotime(date('Y-m-d H:i', $from) . ':00', $from);
+ $to = strtotime(date('Y-m-d H:i', $to) . ':59', $to);
$filter_value = $table_name.'`'.$field_name.'` >= '.$from.' AND '.$table_name.'`'.$field_name.'` <= '.$to;
}
+ else {
+ $filter_value = 'FALSE';
+ }
break;
case 'equals':
@@ -669,38 +679,45 @@
* @param string $search_field
* @param string $value
* @param string $type
+ * @param string $format_option_prefix Format option prefix.
*/
- function processRangeField(&$object, $search_field, $value, $type)
+ function processRangeField(&$object, $search_field, $value, $type, $format_option_prefix = '')
{
- if ( !strlen($value[$type]) ) {
- return false;
+ $value_by_type = $value[$type];
+
+ if ( !strlen($value_by_type) ) {
+ return null;
}
$options = $object->GetFieldOptions($search_field);
$dt_separator = array_key_exists('date_time_separator', $options) ? $options['date_time_separator'] : ' ';
- $value[$type] = trim($value[$type], $dt_separator); // trim any
+ $value_by_type = trim($value_by_type, $dt_separator); // trim any
- $tmp_value = explode($dt_separator, $value[$type], 2);
+ $tmp_value = explode($dt_separator, $value_by_type, 2);
if ( count($tmp_value) == 1 ) {
- $time_format = $this->_getInputTimeFormat($options);
+ $time_format = $this->_getInputTimeFormat($options, $format_option_prefix . 'time_format');
if ( $time_format ) {
// time is missing, but time format available -> guess time and add to date
- $time = ($type == 'from') ? adodb_mktime(0, 0, 0) : adodb_mktime(23, 59, 59);
+ $time = adodb_mktime(0, 0, 0);
$time = adodb_date($time_format, $time);
- $value[$type] .= $dt_separator . $time;
+ $value_by_type .= $dt_separator . $time;
}
}
/** @var kFormatter $formatter */
$formatter = $this->Application->recallObject($options['formatter']);
-
- $value_ts = $formatter->Parse($value[$type], $search_field, $object);
+ $format = $options[$format_option_prefix . 'format'];
+ $value_ts = $formatter->Parse($value_by_type, $search_field, $object, $format);
if ( $object->GetErrorPseudo($search_field) ) {
// invalid format -> ignore this date in search
$object->RemoveError($search_field);
- return false;
+ if ( $format_option_prefix == 'input_' ) {
+ return false;
+ }
+
+ return $this->processRangeField($object, $search_field, $value, $type, 'input_');
}
return $value_ts;
@@ -709,19 +726,21 @@
/**
* Returns InputTimeFormat using given field options
*
- * @param Array $field_options
+ * @param Array $field_options
+ * @param string $format_option_name Format option name.
* @return string
*/
- function _getInputTimeFormat($field_options)
+ function _getInputTimeFormat($field_options, $format_option_name = 'input_time_format')
{
- if ( array_key_exists('input_time_format', $field_options) ) {
- return $field_options['input_time_format'];
+ if ( array_key_exists($format_option_name, $field_options) ) {
+ return $field_options[$format_option_name];
}
/** @var LanguagesItem $lang_current */
$lang_current = $this->Application->recallObject('lang.current');
+ $field_name = str_replace(' ', '', ucwords(str_replace('_', ' ', $format_option_name)));
- return $lang_current->GetDBField('InputTimeFormat');
+ return $lang_current->GetDBField($field_name);
}
/**
Event Timeline
Log In to Comment