From b4d3aad1bb9092516cbdaf9ab7e657306fe74161 Mon Sep 17 00:00:00 2001 From: Shaun Adlam Date: Mon, 17 Jul 2017 15:41:55 +0200 Subject: [PATCH] Update Date.php isset and !isset is not working because the $tmp date values are set to false. Replace with !empty and empty Ex if (!empty($tmp_start_date)) = false because ($tmp_start_date = $this->_is_format_valid($this->attributes['direction'][0])) function _is_format_valid return false and set $tmp_start_date !empty and empty test for isset and if the value is false or '' Add test for if date $obj->direction(array(1, 7)); to add the first array value to the second otherwise it will give error on the 7th day Ex. if today is 2017-07-17 2017-07-18 2017-07-25 gives error because test till 2017-07-24 add the if in line 1147 if $obj->direction(array(5,7)); check for 7 days not working because $this->attributes['direction'][0] not added to $this->attributes['direction'][1] from today add the if in line 1150 if $obj->direction(array('2017-07-18', 7')); to check 7 days didn't work because system_date used and not $this->attributes['direction'][0]) added the same to get the start date if you have the end date line 1189 --- includes/Date.php | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/includes/Date.php b/includes/Date.php index 753f4bb..2703864 100644 --- a/includes/Date.php +++ b/includes/Date.php @@ -1129,7 +1129,7 @@ function _init() ) { // if an exact starting date was given, use that as a starting date - if (isset($tmp_start_date)) $this->first_selectable_date = $tmp_start_date; + if (!empty($tmp_start_date)) $this->first_selectable_date = $tmp_start_date; // otherwise else @@ -1138,13 +1138,19 @@ function _init() $this->first_selectable_date = strtotime('+' . (!is_array($this->attributes['direction']) ? (int)($this->attributes['direction']) : (int)($this->attributes['direction'][0] === true ? 0 : $this->attributes['direction'][0])) . ' day', $system_date); // if an exact ending date was given and the date is after the starting date, use that as a ending date - if (isset($tmp_end_date) && $tmp_end_date >= $this->first_selectable_date) $this->last_selectable_date = $tmp_end_date; + if (!empty($tmp_end_date) && $tmp_end_date >= $this->first_selectable_date) $this->last_selectable_date = $tmp_end_date; // if have information about the ending date - else if (!isset($tmp_end_date) && $this->attributes['direction'][1] !== false && is_array($this->attributes['direction'])) + else if (empty($tmp_end_date) && $this->attributes['direction'][1] !== false && is_array($this->attributes['direction'])) // figure out the ending date - $this->last_selectable_date = strtotime('+' . (int)($this->attributes['direction'][1]) . ' day', $system_date); + if (is_numeric($this->attributes['direction'][0]) && is_numeric($this->attributes['direction'][1])) + $this->last_selectable_date = strtotime('+' . ((int)($this->attributes['direction'][1]) + $this->attributes['direction'][0]). ' day', $system_date); + else + if ($this->_is_format_valid($this->attributes['direction'][0]) && is_numeric($this->attributes['direction'][1])) + $this->last_selectable_date = strtotime('+' . (int)($this->attributes['direction'][1]) . ' day', strtotime($this->attributes['direction'][0])); + else + $this->last_selectable_date = strtotime('+' . (int)($this->attributes['direction'][1]) . ' day', $system_date); } else if ( @@ -1174,18 +1180,24 @@ function _init() $this->last_selectable_date = strtotime('+' . (!is_array($this->attributes['direction']) ? (int)($this->attributes['direction']) : (int)($this->attributes['direction'][0] === false ? 0 : $this->attributes['direction'][0])) . ' day', $system_date); // if an exact starting date was given, and the date is before the ending date, use that as a starting date - if (isset($tmp_start_date) && $tmp_start_date < $this->last_selectable_date) $this->first_selectable_date = $tmp_start_date; + if (!empty($tmp_start_date) && $tmp_start_date < $this->last_selectable_date) $this->first_selectable_date = $tmp_start_date; // if have information about the starting date - else if (!isset($tmp_start_date) && is_array($this->attributes['direction'])) + else if (empty($tmp_start_date) && is_array($this->attributes['direction'])) // figure out the staring date - $this->first_selectable_date = strtotime('-' . (int)($this->attributes['direction'][1]) . ' day'); + if (is_numeric($this->attributes['direction'][0]) && is_numeric($this->attributes['direction'][1])) + $this->first_selectable_date = strtotime('-' . ((int)($this->attributes['direction'][1]) - $this->attributes['direction'][0]) . ' day'); + else + if ($this->_is_format_valid($this->attributes['direction'][1]) && is_numeric($this->attributes['direction'][0])) + $this->first_selectable_date = strtotime($this->attributes['direction'][1]); + else + $this->first_selectable_date = strtotime('-' . (int)($this->attributes['direction'][1]) . ' day'); } // if a first selectable date exists - if (isset($this->first_selectable_date)) { + if (!empty($this->first_selectable_date)) { // extract the date parts $first_selectable_year = date('Y', $this->first_selectable_date); @@ -1195,7 +1207,7 @@ function _init() } // if a last selectable date exists - if (isset($this->last_selectable_date)) { + if (!empty($this->last_selectable_date)) { // extract the date parts $last_selectable_year = date('Y', $this->last_selectable_date); @@ -1205,7 +1217,7 @@ function _init() } // if a first selectable date exists but is disabled, find the actual first selectable date - if (isset($this->first_selectable_date) && $this->_is_disabled($first_selectable_year, $first_selectable_month, $first_selectable_day)) { + if (!empty($this->first_selectable_date) && $this->_is_disabled($first_selectable_year, $first_selectable_month, $first_selectable_day)) { // loop until we find the first selectable year while ($this->_is_disabled($first_selectable_year)) {