hi
I have a ISO_DATE field in a custom table and i want to use the filtering/arguments that date_views provide
but it seem not working
problem is views creates sql based on unix timestamp

what i implemented so far:

hook_views_data:

  $data['temperatures']['datetime'] = array(
    'title' => t('Datetime'),
    'help' => t('Datetime.'),
    'field' => array(
      'handler' => 'date_handler_field_date',
      'click sortable' => TRUE,
      'is date' => TRUE,
    ),
    'filter' => array(
      'handler' => 'date_views_filter_handler',
      'is date' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort_date',
      'is date' => TRUE,
    ),
  );

hook_date_views_fields:

  $values = array(
    // The type of date: DATE_UNIX, DATE_ISO, DATE_DATETIME.
    'sql_type' => DATE_ISO,
    // Timezone handling options: 'none', 'site', 'date', 'utc' .
    'tz_handling' => 'none',
    // Needed only for dates that use 'date' tz_handling.
    'timezone_field' => '',
    // Needed only for dates that use 'date' tz_handling.
    'offset_field' => '',
    // Array of "table.field" values for related fields that should be
    // loaded automatically in the Views SQL.
    'related_fields' => array(),
    // Granularity of this date field's db data.
    'granularity' => array('year', 'month', 'day', 'hour', 'minute', 'second'),
  );

  switch ($field) {
    case 'temperature.datetime':
      return $values;
  }

but in date_views_fields.inc line:145 replaces the sql_type by it's default value: DATE_UNIX

Comments

dalin’s picture

Status: Active » Fixed

I was running into this issue as well, and this ticket helped me to figure out the solution.

In mymodule.views.inc:

function mymodule_views_data() {
 // ...
   $data['mytable']['deadline'] = array(
    'title' => t('Ticket Deadline'),
    'help' => t('Date of ticket deadline.'),
    'field' => array(
      'handler' => 'views_handler_field',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort',
      'help' => t('Sort on a ticket\'s deadline date.'),
    ),
    'filter' => array(
      // It seems that you can put anything in here, Date module will just override it.
      'handler' => 'views_handler_filter_date',
      'help' => t('Filter on a ticket\'s deadline date.'),
    ),
    'argument' => array(
      // It seems that you can put anything in here, Date module will just override it. 
     'handler' => 'date_views_argument_handler_simple',
      'help' => t('Argument on a ticket\'s deadline date.'),
    ),
  );
 // ...
}

And in mymodule.module:

/**
 * Implements hook_date_views_extra_tables()
 */
function mymodule_date_views_extra_tables() {
  return array(
    // mytable contains date columns that are related to nodes.
    'mytable' => 'node',
  );
}

/**
 * Implements hook_date_views_fields().
 */
function mymodule_date_views_fields($field) {
  $values = array(
    // The type of date: DATE_UNIX, DATE_ISO, DATE_DATETIME.
    'sql_type' => DATE_ISO,
    // Timezone handling options: 'none', 'site', 'date', 'utc' .
    'tz_handling' => 'site',
    // Needed only for dates that use 'date' tz_handling.
    'timezone_field' => '',
    // Needed only for dates that use 'date' tz_handling.
    'offset_field' => '',
    // Array of "table.field" values for related fields that should be
    // loaded automatically in the Views SQL.
    'related_fields' => array(),
    // Granularity of this date field's db data.
    'granularity' => array('year', 'month', 'day'),
  );

  switch ($field) {
    // Our custom field uses ISO, not the default UTC.
    case 'mytable.deadline':
      return $values;
  }
}

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.