Projet

Général

Profil

Révision db9ffd17

Ajouté par Assos Assos il y a presque 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/date/date_repeat/date_repeat_calc.inc
173 173
      }
174 174
      if ($rrule['FREQ'] == 'YEARLY') {
175 175
        // Back up to first of year and jump.
176
        $current_day = date_repeat_set_year_day($current_day, NULL, 1, '+', $timezone, $modify_time);
176
        $current_day = date_repeat_set_year_day($current_day, NULL, NULL, 1, '+', $timezone, $modify_time);
177 177
        date_modify($current_day, '+' . $jump . $modify_time);
178 178
      }
179 179
      $finished = date_repeat_is_finished($current_day, $days, $count, $end_date);
......
223 223
    $ordered = date_repeat_days_ordered($week_start_rule);
224 224
    $ordered_keys = array_flip($ordered);
225 225

  
226
    foreach ($rrule['BYDAY'] as $day) {
227
      preg_match("@(-)?([0-9]+)?([SU|MO|TU|WE|TH|FR|SA]{2})@", trim($day), $regs);
228
      if (!empty($regs[2])) {
229
        // Convert parameters into full day name, count, and direction.
230
        $direction_days[] = array(
231
          'day' => $day_names[$regs[3]],
232
          'direction' => !empty($regs[1]) ? $regs[1] : '+',
233
          'direction_count' => $regs[2],
234
          );
226
    if ($rrule['FREQ'] == 'YEARLY' && !empty($rrule['BYMONTH'])) {
227
      // Additional cycle to apply month preferences.
228
      foreach ($rrule['BYMONTH'] as $month) {
229
        foreach ($rrule['BYDAY'] as $day) {
230
          preg_match("@(-)?([0-9]+)?([SU|MO|TU|WE|TH|FR|SA]{2})@", trim($day), $regs);
231
          // Convert parameters into full day name, count, and direction.
232
          // Add leading zero to first 9 months.
233
          if (!empty($regs[2])) {
234
            $direction_days[] = array(
235
              'day' => $day_names[$regs[3]],
236
              'direction' => !empty($regs[1]) ? $regs[1] : '+',
237
              'direction_count' => $regs[2],
238
              'month' => strlen($month) > 1 ? $month : '0' . $month,
239
            );
240
          }
241
          else {
242
            $week_days[$ordered_keys[$regs[3]]] = $day_names[$regs[3]];
243
          }
244
        }
235 245
      }
236
      else {
237
        $week_days[$ordered_keys[$regs[3]]] = $day_names[$regs[3]];
246
    }
247
    else {
248
      foreach ($rrule['BYDAY'] as $day) {
249
        preg_match("@(-)?([0-9]+)?([SU|MO|TU|WE|TH|FR|SA]{2})@", trim($day), $regs);
250
        if (!empty($regs[2])) {
251
          // Convert parameters into full day name, count, and direction.
252
          $direction_days[] = array(
253
            'day' => $day_names[$regs[3]],
254
            'direction' => !empty($regs[1]) ? $regs[1] : '+',
255
            'direction_count' => $regs[2],
256
            'month' => NULL,
257
          );
258
        }
259
        else {
260
          $week_days[$ordered_keys[$regs[3]]] = $day_names[$regs[3]];
261
        }
238 262
      }
239 263
    }
240 264
    ksort($week_days);
......
251 275
            $current_day = date_repeat_set_month_day($current_day, $day['day'], $day['direction_count'], $day['direction'], $timezone, $modify_time);
252 276
          }
253 277
          else {
254
            $current_day = date_repeat_set_year_day($current_day, $day['day'], $day['direction_count'], $day['direction'], $timezone, $modify_time);
278
            $current_day = date_repeat_set_year_day($current_day, $day['month'], $day['day'], $day['direction_count'], $day['direction'], $timezone, $modify_time);
255 279
          }
256 280
          date_repeat_add_dates($days, $current_day, $start_date, $end_date, $exceptions, $rrule);
257 281
        }
......
543 567
 *   If $day is empty, will set to the number of days from the
544 568
 *   beginning or end of the year.
545 569
 */
546
function date_repeat_set_year_day($date_in, $day, $count = 1, $direction = '+', $timezone = 'UTC', $modify_time) {
570
function date_repeat_set_year_day($date_in, $month, $day, $count = 1, $direction = '+', $timezone = 'UTC', $modify_time) {
547 571
  if (is_object($date_in)) {
548 572
    $current_year = date_format($date_in, 'Y');
549 573

  
550 574
    // Reset to the start of the month.
551 575
    // See note above.
552 576
    $datetime = date_format($date_in, DATE_FORMAT_DATETIME);
553
    $datetime = substr_replace($datetime, '01-01', 5, 5);
577
    $month_key = isset($month) ? $month : '01';
578
    $datetime = substr_replace($datetime, $month_key . '-01', 5, 5);
554 579
    $date = new DateObject($datetime, $timezone);
555
    if ($direction == '-') {
556
      // For negative search, start from the end of the year.
557
      date_modify($date, '+1 year' . $modify_time);
580

  
581
    if (isset($month)) {
582
      if ($direction == '-') {
583
        // For negative search, start from the end of the month.
584
        $modifier = '+1 month';
585
      }
586
      else {
587
        // For positive search, back up one day to get outside the
588
        // current month, so we can catch the first of the month.
589
        $modifier = '-1 day';
590
      }
558 591
    }
559 592
    else {
560
      // For positive search, back up one day to get outside the
561
      // current year, so we can catch the first of the year.
562
      date_modify($date, '-1 day' . $modify_time);
593
      if ($direction == '-') {
594
        // For negative search, start from the end of the year.
595
        $modifier = '+1 year';
596
      }
597
      else {
598
        // For positive search, back up one day to get outside the
599
        // current year, so we can catch the first of the year.
600
        $modifier = '-1 day';
601
      }
563 602
    }
603

  
604
    date_modify($date, $modifier . $modify_time);
605

  
564 606
    if (empty($day)) {
565 607
      date_modify($date, $direction . $count . ' days' . $modify_time);
566 608
    }

Formats disponibles : Unified diff