Hi,

My goal is to display a 'datetime' (MySQL) field with Views module, but unfortunately I only get "1970/01/01 - 02:33" (however the date is stored correctly in the field itself).
As I read the documentation and the few related hits I found with Google, it seems that I need to create a hook which specifies how the fields should be handled. I made the followings:
First in hook_views_data:

// Implementing hook_views_data()
function hublist_views_data()
{
	$data = array();
	// [A lot of other fields here]
	// [...]

	// Latest ping date
	$data['hublist']['stat_pingdate'] = array(
		'title' => t('Latest ping attempt'),
		'help' => t('Latest ping attempt'),
		'field' => array(
			'handler' => 'views_handler_field_date',
			'click sortable' => TRUE,
		),
		'filter' => array(
			'handler' => 'views_handler_filter_date',
		),
		'argument' => array(
			'handler' => 'views_handler_argument_date',
		),
		'sort' => array(
			'handler' => 'views_handler_sort_date',
		),
	);

Then I also have this hook in my .module file:

function hublist_date_api_fields($field) {
  $values = array(
    // The type of date: DATE_UNIX, DATE_ISO, DATE_DATETIME.
    'sql_type' => DATE_DATETIME,
    // 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', 'hour', 'minute', 'second'),
  );
  
  switch ($field) {
    case 'hublist.stat_pingdate':
      return $values;
  }
  // The following return may ensure that it return the values without any condition...
  // Just for the case I made the previous switch wrong...
  return $values;
}

Could someone help me what do I wrong?

Comments

fleetcommand’s picture

Title: What do I do wrong with implementing hook_date_api_fields()? » hook_date_api_fields() is not fired (converted from a support request. see first comment)
Category: support » bug

Converted to a bug report. It seems the hook_date_api_fields is not fired at all...

function hublist_date_api_fields($field) {
	watchdog('pinger', 'TEST: DATE API FIELDS HOOK FIRED');

Added the following line to the beginning of my hook, but for some reason it does not appear in the database log which shows that this hook is not fired at all. Updated today to the -dev version to ensure that the bug still present.

dropcube’s picture

chiddicks’s picture

Of note is that in addition to this hook (hook_date_api_fields) you need to declare your tables using hook_date_api_tables(). If you implement the former and not the latter your hook will be called for other fields but not your own.

ARUN AK’s picture

@chiddicks, could you please provide any example code of hook_date_api_tables?