You are here

function _signup_date_sql_math in Signup 6.2

Same name and namespace in other branches
  1. 5.2 includes/date.5x-2.inc \_signup_date_sql_math()

Helper function to handle date math across DB types.

This can be removed once date_api_sql.inc revision 1.9.2.3.2.28 is widely available in an official release.

Parameters

$field: The field to be adjusted.

$direction: Either ADD or SUB.

$count: The number of values to adjust.

$granularity: The granularity of the adjustment, should be singular, like SECOND, MINUTE, DAY, HOUR.

1 call to _signup_date_sql_math()
_signup_date_reminder_sql in includes/date.inc

File

includes/date.inc, line 440
Code to support using CCK date fields for time-based signup functionality.

Code

function _signup_date_sql_math($field, $direction, $count, $granularity) {
  $granularity = strtoupper($granularity);
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      if ($direction == 'ADD') {
        return "DATE_ADD({$field}, INTERVAL {$count} {$granularity})";
      }
      else {
        return "DATE_SUB({$field}, INTERVAL {$count} {$granularity})";
      }
    case 'pgsql':
      $granularity .= 'S';
      if ($direction == 'ADD') {
        return "({$field} + INTERVAL '{$count} {$granularity}')";
      }
      else {
        return "({$field} - INTERVAL '{$count} {$granularity}')";
      }
  }
  return $field;
}