You are here

function commerce_coupon_date_evaluate_date_build in Commerce Coupon 7.2

Inline conditions build callback: evaluate date range.

1 string reference to 'commerce_coupon_date_evaluate_date_build'
commerce_coupon_date_inline_conditions_info in modules/date/commerce_coupon_date.module
Implements hook_inline_conditions_info.

File

modules/date/commerce_coupon_date.module, line 22

Code

function commerce_coupon_date_evaluate_date_build($coupon, $start = NULL, $end = NULL) {

  // We want end to be the end of the day on whatever day they choose.
  if ($end) {
    $end_timestamp = strtotime('+1 day', $end);
  }

  // Error message building blocks.
  $date_format = 'D, m/d/Y';

  // Comparisons
  $lower_pass = REQUEST_TIME >= $start;
  $upper_pass = REQUEST_TIME <= $end_timestamp;
  if ($start && $end) {
    $outcome = $lower_pass && $upper_pass;
    $message = t('Unfortunately, this coupon is only valid starting %start until %end.', array(
      '%start' => format_date($start, 'custom', $date_format),
      '%end' => format_date($end, 'custom', $date_format),
    ));
  }
  else {
    if ($end) {
      $outcome = $upper_pass;
      $message = t('Unfortunately, this coupon is only valid until %end.', array(
        '%end' => format_date($end, 'custom', $date_format),
      ));
    }
    else {
      if ($start) {
        $outcome = $lower_pass;
        $message = t('Unfortunately, this coupon is only valid starting %start.', array(
          '%start' => format_date($start, 'custom', $date_format),
        ));
      }
    }
  }
  if (!$outcome) {
    $error =& drupal_static('commerce_coupon_error_' . strtolower($coupon->code));
    $error = $message;
  }
  return $outcome;
}