function commerce_discount_date_condition in Commerce Discount 7
Rules condition: Check discount can be applied.
2 string references to 'commerce_discount_date_condition'
File
- ./
commerce_discount.rules.inc, line 1580  - Rules integration for the Commerce Discount module.
 
Code
function commerce_discount_date_condition($discount_name) {
  if (!($discount = entity_load_single('commerce_discount', $discount_name))) {
    return FALSE;
  }
  if (!isset($discount->commerce_discount_date[LANGUAGE_NONE])) {
    return TRUE;
  }
  $discount_date = $discount->commerce_discount_date[LANGUAGE_NONE][0];
  $time = time();
  $start_date = new DateTime();
  $start_date
    ->setTimestamp($discount_date['value']);
  $start_date
    ->setTime(0, 0, 0);
  $start_date_timestamp = $start_date
    ->getTimestamp();
  $end_date = new DateTime();
  $end_date
    ->setTimestamp($discount_date['value2']);
  $end_date
    ->setTime(24, 0, 0);
  $end_date_timestamp = $end_date
    ->getTimestamp();
  return $time >= $start_date_timestamp && $time <= $end_date_timestamp;
}