You are here

function date_field_get_sql_handler in Date 7.3

Same name and namespace in other branches
  1. 5.2 date/date.module \date_field_get_sql_handler()
  2. 6.2 date/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()

Generates a Date API SQL handler for the given date field.

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

Parameters

array $field: The $field array.

string $compare_tz: The timezone used for comparison values in the SQL.

Deprecated

Will be removed at some time in the future.

File

./date.module, line 807

Code

function date_field_get_sql_handler(array $field, $compare_tz = NULL) {
  module_load_include('inc', 'date_api', 'date_api_sql');
  $db_info = date_api_database_info($field);

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

  // If this date field stores a timezone in the DB, tell the handler about it.
  if ($field['settings']['tz_handling'] == 'date') {
    $handler->db_timezone_field = $db_info['columns']['timezone']['column'];
  }
  else {
    $handler->db_timezone = date_get_timezone_db($field['settings']['tz_handling']);
  }
  if (empty($compare_tz)) {
    $compare_tz = date_get_timezone($field['settings']['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;
}