You are here

function date_field_get_sql_handler in Date 5.2

Same name and namespace in other branches
  1. 6.2 date/date.module \date_field_get_sql_handler()
  2. 7.3 date.module \date_field_get_sql_handler()
  3. 7 date.module \date_field_get_sql_handler()
  4. 7.2 date.module \date_field_get_sql_handler()

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

The handler will be set up to make the correct timezone adjustments for the field settings.

Parameters

$field:

  • a $field array.

$compare_tz:

  • the timezone used for comparison values in the SQL.

File

date/date.module, line 663
Defines date/time field types for the Content Construction Kit (CCK).

Code

function date_field_get_sql_handler($field, $compare_tz = NULL) {
  require_once './' . drupal_get_path('module', 'date_api') . '/date_api_sql.inc';
  $db_info = content_database_info($field);

  // 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') {
    $handler->db_timezone_field = $db_info['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, force the DB
  // to use UTC so no timezone conversions get added to things like
  // NOW() or FROM_UNIXTIME().
  $handler
    ->set_db_timezone();
  return $handler;
}