diff options
author | sten <stenmarsh938@gmail.com> | 2016-03-25 16:57:05 +0300 |
---|---|---|
committer | sten <stenmarsh938@gmail.com> | 2016-03-25 16:57:05 +0300 |
commit | bb3e93a78c9fb18a7ed84bc69f9cf60621a25e99 (patch) | |
tree | a82ef5946f916eee87e3fca907357fdb742661ea | |
parent | fd356a54b000add786a5feac133de3c6ecb2aab4 (diff) | |
download | scheduler-helper-php-bb3e93a78c9fb18a7ed84bc69f9cf60621a25e99.zip scheduler-helper-php-bb3e93a78c9fb18a7ed84bc69f9cf60621a25e99.tar.gz scheduler-helper-php-bb3e93a78c9fb18a7ed84bc69f9cf60621a25e99.tar.bz2 |
Fix recurring months misplacing.
-rw-r--r-- | RecurringType.php | 31 | ||||
-rwxr-xr-x | SchedulerHelperDate.php | 12 |
2 files changed, 25 insertions, 18 deletions
diff --git a/RecurringType.php b/RecurringType.php index 4a09d59..7d48f30 100644 --- a/RecurringType.php +++ b/RecurringType.php @@ -261,36 +261,31 @@ class RecurringType { } //Correct end date interval if it smaller then recurring end date. - if ($intervalEndDateStamp > $recurringEndDateStamp){ + if ($intervalEndDateStamp > $recurringEndDateStamp) { $intervalEndDateStamp = $recurringEndDateStamp; $recurringInterval["end_date_stamp"] = $intervalEndDateStamp; } $type = $this->getRecurringTypeValue(); - //If recurring type is "year" then exit, else add months. - if ($type == self::REC_TYPE_DAY || $type == self::REC_TYPE_WEEK) { - if($recurringStartDateStamp < $intervalStartDateStamp) { + if ($recurringStartDateStamp < $intervalStartDateStamp) { + if ($type == self::REC_TYPE_DAY || $type == self::REC_TYPE_WEEK) { $step = $this->_transpose_size[$type] * $this->getRecurringTypeStepValue(); $day = 24 * 60 * 60; $delta = floor(($intervalStartDateStamp - $recurringStartDateStamp) / ($day * $step)); $recurringInterval["start_date_stamp"] = $recurringStartDateStamp + $delta * $step * $day; - } - } - else { - $differenceStartDates = SchedulerHelperDate::differenceBetweenDates($intervalStartDateStamp, $recurringStartDateStamp); - $dateUnits = SchedulerHelperDate::$DATE_UNITS; - - //Add years. - $recurringInterval["start_date_stamp"] = SchedulerHelperDate::addYears($recurringStartDateStamp, $differenceStartDates[$dateUnits["year"]]); + } else { + $step = $this->_transpose_size[$type] * $this->getRecurringTypeStepValue(); + $intStartDetails = SchedulerHelperDate::getDateInfo($intervalStartDateStamp); + $recStartDetails = SchedulerHelperDate::getDateInfo($recurringStartDateStamp); + $delta = ceil((($intStartDetails["year"] * 12 + $intStartDetails["month"]) - ($recStartDetails["year"] * 12 + $recStartDetails["month"])) / $step); - if ($type == self::REC_TYPE_YEAR) - return $recurringInterval; + $date = new DateTime(); + $date->setTimestamp($recurringStartDateStamp); - //Add months. - $recurringInterval["start_date_stamp"] = SchedulerHelperDate::addMonths($recurringInterval["start_date_stamp"], $differenceStartDates[$dateUnits["month"]]); - if ($type == self::REC_TYPE_MONTH) - return $recurringInterval; + $date->setDate($recStartDetails["year"], $recStartDetails["month"] + $delta * $step, $recStartDetails["day"]); + $recurringInterval["start_date_stamp"] = $date->getTimestamp(); + } } return $recurringInterval; diff --git a/SchedulerHelperDate.php b/SchedulerHelperDate.php index 33635a9..a0e5f21 100755 --- a/SchedulerHelperDate.php +++ b/SchedulerHelperDate.php @@ -89,6 +89,18 @@ class SchedulerHelperDate $weekDay = getdate($timestamp)["wday"]; return $weekDay; } + + static public function getDateInfo($timestamp) + { + $result = array(); + $date = new DateTime(); + $date->setTimestamp($timestamp); + foreach (self::$DATE_UNITS as $key => $value) { + $result[$key] = $date->format($value); + } + + return $result; + } static public function addDate($timestamp, $unit, $count) { $date = new DateTime(); |