Révision b720ea3e
Ajouté par Assos Assos il y a plus de 8 ans
drupal7/sites/all/modules/date/date_repeat/date_repeat_calc.inc | ||
---|---|---|
53 | 53 |
// Create a date object for the start and end dates. |
54 | 54 |
$start_date = new DateObject($start, $timezone); |
55 | 55 |
|
56 |
// Versions of PHP greater than PHP 5.3.5 require that we set an explicit time when |
|
57 |
// using date_modify() or the time may not match the original value. Adding this |
|
58 |
// modifier gives us the same results in both older and newer versions of PHP. |
|
56 |
// Versions of PHP greater than PHP 5.3.5 require |
|
57 |
// that we set an explicit time when using date_modify() |
|
58 |
// or the time may not match the original value. |
|
59 |
// Adding this modifier gives us the same results in both older |
|
60 |
// and newer versions of PHP. |
|
59 | 61 |
$modify_time = ' ' . $start_date->format('g:ia'); |
60 | 62 |
|
61 | 63 |
// If the rule has an UNTIL, see if that is earlier than the end date. |
... | ... | |
91 | 93 |
} |
92 | 94 |
|
93 | 95 |
// Make sure DAILY frequency isn't used in places it won't work; |
94 |
if (!empty($rrule['BYMONTHDAY']) && !in_array($rrule['FREQ'], array('MONTHLY', 'YEARLY'))) { |
|
96 |
if (!empty($rrule['BYMONTHDAY']) && |
|
97 |
!in_array($rrule['FREQ'], array('MONTHLY', 'YEARLY'))) { |
|
95 | 98 |
$rrule['FREQ'] = 'MONTHLY'; |
96 | 99 |
} |
97 |
elseif (!empty($rrule['BYDAY']) && !in_array($rrule['FREQ'], array('MONTHLY', 'WEEKLY', 'YEARLY'))) { |
|
100 |
elseif (!empty($rrule['BYDAY']) |
|
101 |
&& !in_array($rrule['FREQ'], array('MONTHLY', 'WEEKLY', 'YEARLY'))) { |
|
98 | 102 |
$rrule['FREQ'] = 'WEEKLY'; |
99 |
}
|
|
103 |
} |
|
100 | 104 |
|
101 | 105 |
// Find the time period to jump forward between dates. |
102 | 106 |
switch ($rrule['FREQ']) { |
103 |
case 'DAILY': |
|
104 |
$jump = $interval . ' days'; |
|
105 |
break; |
|
106 |
case 'WEEKLY': |
|
107 |
$jump = $interval . ' weeks'; |
|
108 |
break; |
|
109 |
case 'MONTHLY': |
|
110 |
$jump = $interval . ' months'; |
|
111 |
break; |
|
112 |
case 'YEARLY': |
|
113 |
$jump = $interval . ' years'; |
|
114 |
break; |
|
107 |
case 'DAILY': |
|
108 |
$jump = $interval . ' days'; |
|
109 |
break; |
|
110 |
|
|
111 |
case 'WEEKLY': |
|
112 |
$jump = $interval . ' weeks'; |
|
113 |
break; |
|
114 |
|
|
115 |
case 'MONTHLY': |
|
116 |
$jump = $interval . ' months'; |
|
117 |
break; |
|
118 |
|
|
119 |
case 'YEARLY': |
|
120 |
$jump = $interval . ' years'; |
|
121 |
break; |
|
115 | 122 |
} |
116 | 123 |
$rrule = date_repeat_adjust_rrule($rrule, $start_date); |
117 | 124 |
|
... | ... | |
135 | 142 |
$direction_days[$day] = array( |
136 | 143 |
'direction' => !empty($regs[1]) ? $regs[1] : '+', |
137 | 144 |
'direction_count' => $regs[2], |
138 |
);
|
|
145 |
); |
|
139 | 146 |
} |
140 | 147 |
} |
141 | 148 |
while (!$finished) { |
... | ... | |
198 | 205 |
|
199 | 206 |
else { |
200 | 207 |
|
201 |
// More complex searches for day names and criteria like '-1SU' or '2TU,2TH', |
|
202 |
// require that we interate through the whole time period checking each BYDAY. |
|
208 |
// More complex searches for day names and criteria |
|
209 |
// like '-1SU' or '2TU,2TH', require that we interate through |
|
210 |
// the whole time period checking each BYDAY. |
|
203 | 211 |
|
204 | 212 |
// Create helper array to pull day names out of iCal day strings. |
205 | 213 |
$day_names = date_repeat_dow_day_options(FALSE); |
... | ... | |
303 | 311 |
// period, then jumping ahead to the next week, month, or year, |
304 | 312 |
// an INTERVAL at a time. |
305 | 313 |
|
306 |
if (!empty($week_days) && in_array($rrule['FREQ'], array('MONTHLY', 'WEEKLY', 'YEARLY'))) { |
|
314 |
if (!empty($week_days) && |
|
315 |
in_array($rrule['FREQ'], array('MONTHLY', 'WEEKLY', 'YEARLY'))) { |
|
307 | 316 |
$finished = FALSE; |
308 | 317 |
$current_day = clone($start_date); |
309 | 318 |
$format = $rrule['FREQ'] == 'YEARLY' ? 'Y' : 'n'; |
... | ... | |
322 | 331 |
$moved = FALSE; |
323 | 332 |
foreach ($week_days as $delta => $day) { |
324 | 333 |
// Find the next occurence of each day in this week, only add it |
325 |
// if we are still in the current month or year. The date_repeat_add_dates |
|
326 |
// function is insufficient to test whether to include this date |
|
334 |
// if we are still in the current month or year. |
|
335 |
// The date_repeat_add_dates function is insufficient |
|
336 |
// to test whether to include this date |
|
327 | 337 |
// if we are using a rule like 'every other month', so we must |
328 | 338 |
// explicitly test it here. |
329 | 339 |
|
... | ... | |
370 | 380 |
date_modify($current_day, '+1 ' . $week_start_day . $modify_time); |
371 | 381 |
date_modify($current_day, '-1 week' . $modify_time); |
372 | 382 |
break; |
383 |
|
|
373 | 384 |
case 'MONTHLY': |
374 | 385 |
date_modify($current_day, '-' . (date_format($current_day, 'j') - 1) . ' days' . $modify_time); |
375 | 386 |
date_modify($current_day, '-1 month' . $modify_time); |
376 | 387 |
break; |
388 |
|
|
377 | 389 |
case 'YEARLY': |
378 | 390 |
date_modify($current_day, '-' . date_format($current_day, 'z') . ' days' . $modify_time); |
379 | 391 |
date_modify($current_day, '-1 year' . $modify_time); |
... | ... | |
387 | 399 |
} |
388 | 400 |
} |
389 | 401 |
|
390 |
// add additional dates
|
|
402 |
// Add additional dates.
|
|
391 | 403 |
foreach ($additions as $addition) { |
392 | 404 |
$date = new dateObject($addition . ' ' . $start_date->format('H:i:s'), $timezone); |
393 | 405 |
$days[] = date_format($date, DATE_FORMAT_DATETIME); |
... | ... | |
426 | 438 |
// position rules make no sense in other periods and just add complexity. |
427 | 439 |
|
428 | 440 |
elseif (!empty($rrule['BYDAY']) && !in_array($rrule['FREQ'], array('MONTHLY', 'YEARLY'))) { |
429 |
foreach ($rrule['BYDAY'] as $delta => $BYDAY) {
|
|
430 |
$rrule['BYDAY'][$delta] = substr($BYDAY, -2);
|
|
441 |
foreach ($rrule['BYDAY'] as $delta => $by_day) {
|
|
442 |
$rrule['BYDAY'][$delta] = substr($by_day, -2);
|
|
431 | 443 |
} |
432 | 444 |
} |
433 | 445 |
|
... | ... | |
442 | 454 |
* and that it meets other criteria in the RRULE. |
443 | 455 |
*/ |
444 | 456 |
function date_repeat_add_dates(&$days, $current_day, $start_date, $end_date, $exceptions, $rrule) { |
445 |
if (isset($rrule['COUNT']) && sizeof($days) >= $rrule['COUNT']) {
|
|
457 |
if (isset($rrule['COUNT']) && count($days) >= $rrule['COUNT']) {
|
|
446 | 458 |
return FALSE; |
447 | 459 |
} |
448 | 460 |
$formatted = date_format($current_day, DATE_FORMAT_DATETIME); |
... | ... | |
456 | 468 |
return FALSE; |
457 | 469 |
} |
458 | 470 |
if (!empty($rrule['BYDAY'])) { |
459 |
$BYDAYS = $rrule['BYDAY'];
|
|
460 |
foreach ($BYDAYS as $delta => $BYDAY) {
|
|
461 |
$BYDAYS[$delta] = substr($BYDAY, -2);
|
|
471 |
$by_days = $rrule['BYDAY'];
|
|
472 |
foreach ($by_days as $delta => $by_day) {
|
|
473 |
$by_days[$delta] = substr($by_day, -2);
|
|
462 | 474 |
} |
463 |
if (!in_array(date_repeat_dow2day(date_format($current_day, 'w')), $BYDAYS)) {
|
|
475 |
if (!in_array(date_repeat_dow2day(date_format($current_day, 'w')), $by_days)) {
|
|
464 | 476 |
return FALSE; |
465 |
}} |
|
477 |
} |
|
478 |
} |
|
466 | 479 |
if (!empty($rrule['BYYEAR']) && !in_array(date_format($current_day, 'Y'), $rrule['BYYEAR'])) { |
467 | 480 |
return FALSE; |
468 | 481 |
} |
... | ... | |
472 | 485 |
if (!empty($rrule['BYMONTHDAY'])) { |
473 | 486 |
// Test month days, but only if there are no negative numbers. |
474 | 487 |
$test = TRUE; |
475 |
$BYMONTHDAYS = array();
|
|
488 |
$by_month_days = array();
|
|
476 | 489 |
foreach ($rrule['BYMONTHDAY'] as $day) { |
477 | 490 |
if ($day > 0) { |
478 |
$BYMONTHDAYS[] = $day;
|
|
491 |
$by_month_days[] = $day;
|
|
479 | 492 |
} |
480 | 493 |
else { |
481 | 494 |
$test = FALSE; |
482 | 495 |
break; |
483 | 496 |
} |
484 | 497 |
} |
485 |
if ($test && !empty($BYMONTHDAYS) && !in_array(date_format($current_day, 'j'), $BYMONTHDAYS)) {
|
|
498 |
if ($test && !empty($by_month_days) && !in_array(date_format($current_day, 'j'), $by_month_days)) {
|
|
486 | 499 |
return FALSE; |
487 | 500 |
} |
488 | 501 |
} |
... | ... | |
499 | 512 |
* Stop when $current_day is greater than $end_date or $count is reached. |
500 | 513 |
*/ |
501 | 514 |
function date_repeat_is_finished($current_day, $days, $count, $end_date) { |
502 |
if (($count && sizeof($days) >= $count)
|
|
515 |
if (($count && count($days) >= $count)
|
|
503 | 516 |
|| (!empty($end_date) && date_format($current_day, 'U') > date_format($end_date, 'U'))) { |
504 | 517 |
return TRUE; |
505 | 518 |
} |
... | ... | |
517 | 530 |
* If $day is empty, will set to the number of days from the |
518 | 531 |
* beginning or end of the month. |
519 | 532 |
*/ |
520 |
function date_repeat_set_month_day($date_in, $day, $count = 1, $direction = '+', $timezone = 'UTC', $modify_time) { |
|
533 |
function date_repeat_set_month_day($date_in, $day, $count = 1, $direction = '+', $timezone = 'UTC', $modify_time = '') {
|
|
521 | 534 |
if (is_object($date_in)) { |
522 | 535 |
$current_month = date_format($date_in, 'n'); |
523 | 536 |
|
... | ... | |
567 | 580 |
* If $day is empty, will set to the number of days from the |
568 | 581 |
* beginning or end of the year. |
569 | 582 |
*/ |
570 |
function date_repeat_set_year_day($date_in, $month, $day, $count = 1, $direction = '+', $timezone = 'UTC', $modify_time) { |
|
583 |
function date_repeat_set_year_day($date_in, $month, $day, $count = 1, $direction = '+', $timezone = 'UTC', $modify_time = '') {
|
|
571 | 584 |
if (is_object($date_in)) { |
572 | 585 |
$current_year = date_format($date_in, 'Y'); |
573 | 586 |
|
... | ... | |
620 | 633 |
} |
621 | 634 |
} |
622 | 635 |
return $date_in; |
623 |
} |
|
636 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules