diff options
author | AlexKlimenkov <shurick.klimenkov@gmail.com> | 2016-03-25 17:14:56 +0300 |
---|---|---|
committer | AlexKlimenkov <shurick.klimenkov@gmail.com> | 2016-03-25 17:14:56 +0300 |
commit | 7f1e3d9219f90493aeac691aba2ea8f7bc19e05b (patch) | |
tree | 5df3947370df2abf09691252f164b7dcfc7a331d | |
parent | 3302a00e737f2039f4fb4075d21e5d597bdeff24 (diff) | |
parent | a3b22ec9ff365adec101c55c995ab4e0017e0e7e (diff) | |
download | scheduler-helper-php-7f1e3d9219f90493aeac691aba2ea8f7bc19e05b.zip scheduler-helper-php-7f1e3d9219f90493aeac691aba2ea8f7bc19e05b.tar.gz scheduler-helper-php-7f1e3d9219f90493aeac691aba2ea8f7bc19e05b.tar.bz2 |
Merge pull request #22 from mperednya/master
Fix month events recurrings start interval misplacing
-rw-r--r-- | RecurringType.php | 31 | ||||
-rwxr-xr-x | SchedulerHelperDate.php | 12 | ||||
-rw-r--r-- | tests/Data_getData/MonthRecurrings2/source.json | 42 | ||||
-rw-r--r-- | tests/Data_getData/MonthRecurrings2/target.json | 30 | ||||
-rw-r--r-- | tests/Data_getData/YearRecurrings/source.json | 33 | ||||
-rw-r--r-- | tests/Data_getData/YearRecurrings/target.json | 30 |
6 files changed, 83 insertions, 95 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(); diff --git a/tests/Data_getData/MonthRecurrings2/source.json b/tests/Data_getData/MonthRecurrings2/source.json index 4ff1a21..900bbc0 100644 --- a/tests/Data_getData/MonthRecurrings2/source.json +++ b/tests/Data_getData/MonthRecurrings2/source.json @@ -3,39 +3,11 @@ "start_date": "2016-03-01 00:00:00", "end_date": "2016-04-01 00:00:00" }, - "data": [ - { - "start_date": "2016-01-01 06:50:00", - "end_date": "9999-02-01 00:00:00", - "text": "Month Event 1", - "id": "2", - "event_pid": "", - "event_length": "25800", - "rec_pattern": "month_2___", - "rec_type": "month_2___#no", - "!nativeeditor_status": "" - }, - { - "start_date": "2016-01-01 00:00:00", - "end_date": "9999-02-01 00:00:00", - "text": "Month Event 2", - "id": "3", - "event_pid": "", - "event_length": "300", - "rec_pattern": "month_1_1_1_", - "rec_type": "month_1_1_1_#no", - "!nativeeditor_status": "" - }, - { - "start_date": "2016-01-02 08:00:00", - "end_date": "9999-02-01 00:00:00", - "text": "Month Event 3", - "id": "4", - "event_pid": "", - "event_length": "21600", - "rec_pattern": "month_2_0_2_", - "rec_type": "month_2_0_2_#no", - "!nativeeditor_status": "" - } - ] + "data": [{ "id": "2", "start_date": "2016-01-01 06:50:00", "end_date": "9999-02-01 00:00:00", "text": "Month Event 1", "rec_type": "month_2___#no", "event_pid": "0", "event_length": "25800", "rec_pattern": "month_2___"}, + { "id": "3", "start_date": "2016-01-01 00:00:00", "end_date": "9999-02-01 00:00:00", "text": "Month Event 2", "rec_type": "month_1_1_1_#no", "event_pid": "0", "event_length": "300", "rec_pattern": "month_1_1_1_"}, + { "id": "4", "start_date": "2016-01-02 08:00:00", "end_date": "9999-02-01 00:00:00", "text": "Month Event 3", "rec_type": "month_2_0_2_#no", "event_pid": "0", "event_length": "21600", "rec_pattern": "month_2_0_2_"}, + { "id": "5", "start_date": "2016-02-01 06:20:00", "end_date": "9999-02-01 00:00:00", "text": "Month Event 4", "rec_type": "month_2_1_2_#no", "event_pid": "", "event_length": "6000", "rec_pattern": "month_2_1_2_"}, + { "id": "6", "start_date": "2016-02-03 00:00:00", "end_date": "9999-02-01 00:00:00", "text": "Month Event 5", "rec_type": "month_2___#no", "event_pid": "", "event_length": "300", "rec_pattern": "month_2___"}, + { "id": "7", "start_date": "2016-01-03 00:00:00", "end_date": "9999-02-01 00:00:00", "text": "Month Event 6", "rec_type": "month_2___#no", "event_pid": "", "event_length": "300", "rec_pattern": "month_2___"}, + { "id": "8", "start_date": "2016-01-01 00:00:00", "end_date": "9999-02-01 00:00:00", "text": "Month Event 7", "rec_type": "month_2_1_1_#no", "event_pid": "", "event_length": "300", "rec_pattern": "month_2_1_1_"}] }
\ No newline at end of file diff --git a/tests/Data_getData/MonthRecurrings2/target.json b/tests/Data_getData/MonthRecurrings2/target.json index 23255db..6803af8 100644 --- a/tests/Data_getData/MonthRecurrings2/target.json +++ b/tests/Data_getData/MonthRecurrings2/target.json @@ -1,31 +1,3 @@ { - "data": [ - { - "start_date": "2016-03-01 06:50:00", - "end_date": "2016-03-01 14:00:00", - "event_pid": "0", - "text": "Month Event 1", - "id": "2", - "rec_type": "month_2___#no", - "event_length": 25800 - }, - { - "start_date": "2016-03-07 00:00:00", - "end_date": "2016-03-07 00:05:00", - "event_pid": "0", - "text": "Month Event 2", - "id": "3", - "rec_type": "month_1_1_1_#no", - "event_length": 300 - }, - { - "start_date": "2016-03-13 08:00:00", - "end_date": "2016-03-13 14:00:00", - "event_pid": "0", - "text": "Month Event 3", - "id": "4", - "rec_type": "month_2_0_2_#no", - "event_length": 21600 - } - ] + "data": [{"start_date":"2016-03-01 06:50:00","end_date":"2016-03-01 14:00:00","event_pid":"0","text":"Month Event 1","id":"2","rec_type":"month_2___#no","event_length":"25800"},{"start_date":"2016-03-07 00:00:00","end_date":"2016-03-07 00:05:00","event_pid":"0","text":"Month Event 2","id":"3","rec_type":"month_1_1_1_#no","event_length":"300"},{"start_date":"2016-03-13 08:00:00","end_date":"2016-03-13 14:00:00","event_pid":"0","text":"Month Event 3","id":"4","rec_type":"month_2_0_2_#no","event_length":"21600"},{"start_date":"2016-03-03 00:00:00","end_date":"2016-03-03 00:05:00","event_pid":"0","text":"Month Event 6","id":"7","rec_type":"month_2___#no","event_length":300},{"start_date":"2016-03-07 00:00:00","end_date":"2016-03-07 00:05:00","event_pid":"0","text":"Month Event 7","id":"8","rec_type":"month_2_1_1_#no","event_length":300}] }
\ No newline at end of file diff --git a/tests/Data_getData/YearRecurrings/source.json b/tests/Data_getData/YearRecurrings/source.json index 67f1923..8397d6f 100644 --- a/tests/Data_getData/YearRecurrings/source.json +++ b/tests/Data_getData/YearRecurrings/source.json @@ -5,6 +5,16 @@ }, "data": [ { + "id": "1", + "start_date": "2016-01-01 00:00:00", + "end_date": "9999-02-01 00:00:00", + "text": "Year Event 6", + "rec_type": "year_1_1_1_#no", + "event_pid": "0", + "event_length": "300", + "rec_pattern": "year_1_1_1_" + }, + { "id": "7", "start_date": "2015-01-01 00:00:00", "end_date": "2018-01-01 00:00:00", @@ -55,15 +65,24 @@ "rec_pattern": "year_1_7_4_" }, { - "start_date": "2016-01-01 00:00:00", + "id": "12", + "start_date": "2015-01-01 09:00:00", "end_date": "9999-02-01 00:00:00", - "text": "Year Event 6", - "id": "1", - "event_pid": "", - "event_length": "300", - "rec_pattern": "year_1_1_1_", + "text": "Year Event 7", "rec_type": "year_1_1_1_#no", - "!nativeeditor_status": "" + "event_pid": "", + "event_length": "5400", + "rec_pattern": "year_1_1_1_" + }, + { + "id": "13", + "start_date": "2014-01-01 09:00:00", + "end_date": "9999-02-01 00:00:00", + "text": "Year Event 8", + "rec_type": "year_1_1_2_#no", + "event_pid": "", + "event_length": "14700", + "rec_pattern": "year_1_1_2_" } ] }
\ No newline at end of file diff --git a/tests/Data_getData/YearRecurrings/target.json b/tests/Data_getData/YearRecurrings/target.json index 36a2802..12cac4b 100644 --- a/tests/Data_getData/YearRecurrings/target.json +++ b/tests/Data_getData/YearRecurrings/target.json @@ -1,6 +1,15 @@ { "data": [ { + "start_date": "2016-01-04 00:00:00", + "end_date": "2016-01-04 00:05:00", + "event_pid": "0", + "text": "Year Event 6", + "id": "1", + "rec_type": "year_1_1_1_#no", + "event_length": "300" + }, + { "start_date": "2016-01-01 00:00:00", "end_date": "2016-01-01 00:05:00", "event_pid": "0", @@ -43,16 +52,25 @@ "text": "Year Event 5", "id": "11", "rec_type": "year_1_7_4_#no", - "event_length": 300 + "event_length": "300" }, { - "start_date": "2016-01-04 00:00:00", - "end_date": "2016-01-04 00:05:00", + "start_date": "2016-01-04 09:00:00", + "end_date": "2016-01-04 10:30:00", "event_pid": "0", - "text": "Year Event 6", - "id": "1", + "text": "Year Event 7", + "id": "12", "rec_type": "year_1_1_1_#no", - "event_length": 300 + "event_length": 5400 + }, + { + "start_date": "2016-01-11 09:00:00", + "end_date": "2016-01-11 13:05:00", + "event_pid": "0", + "text": "Year Event 8", + "id": "13", + "rec_type": "year_1_1_2_#no", + "event_length": 14700 } ] }
\ No newline at end of file |