You are here

function _signup_date_sql_handler in Signup 6.2

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

Generate a DateAPI SQL handler for the given CCK date field.

This can be removed once revision 1.61.2.4.2.32 is widely available in an official release.

2 calls to _signup_date_sql_handler()
_signup_date_autoclose_sql in includes/date.inc
_signup_date_reminder_sql in includes/date.inc

File

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

Code

function _signup_date_sql_handler($field, $compare_tz = NULL) {

  // Workaround for a bug in DateAPI upto 6.x-2.0-rc5.
  static $mysql_db_offset_set = FALSE;
  module_load_include('inc', 'date_api', 'date_api_sql');

  // Create a DateAPI SQL handler class for this field type.
  $handler = new date_sql_handler();
  $handler
    ->construct($field['type']);

  // If this date field stores a timezone in the DB, tell the handler about it.
  if ($field['tz_handling'] == 'date') {

    // The field has a date column
    $handler->db_timezone_field = $field['database']['columns']['timezone']['column'];
  }
  else {
    $handler->db_timezone = date_get_timezone_db($field['tz_handling']);
  }
  if (empty($compare_tz)) {
    $compare_tz = date_get_timezone($field['tz_handling']);
  }
  $handler->local_timezone = $compare_tz;

  // Now that the handler is properly initialized, tell the DB what TZ to use.
  $handler
    ->set_db_timezone();

  // Up to and including DateAPI 6.x-2.0-rc5, the previous call only worked
  // for mysqli and pgsql. It was a no-op on mysql itself, so in that case, we
  // have to do the work ourselves here or datestamp fields don't work.
  if ($GLOBALS['db_type'] == 'mysql' && !$mysql_db_offset_set && version_compare(db_version(), '4.1.3', '>=')) {
    db_query("SET @@session.time_zone = '+00:00'");
    $mysql_db_offset_set = TRUE;
  }
  return $handler;
}