It's not possible to filter a view by an hms field, for example duration. Say I create a view where one of the fields is an hms field with duration in the format of h:mm:ss. I then want to filter by all nodes with less than or greater than the duration that I enter.

Any solution to this?

Comments

hmm yeah you can, but you must enter the duration in seconds. Not so fancy :)

I have no quick fix for this, probably need to write a views plugin.

A views plugin would be great indeed. This is a functionality that I really need, but I'm not well-traversed enough with programming to know how to do.

Until such a Views plugin comes, what I needed was a drop down with all the existing HMS values in the database. The following snippet accomplishes that (you need to adjust to your module and tables/field names. Clear the cache for it to work.

<?php
function dragon_misc_form_views_exposed_form_alter(&$form, $form_state, $form_id) {
// adjust name above to be: modulename_form_views_exposed_form_alter
 
if ($form['#id'] == 'views-exposed-form-dragon-calc-page') {
   
// adjust above to your form ID, search the HTML for your view for: 'views-exposed-form'
   
$options1 = array();
   
$result1 = db_query('SELECT DISTINCT(field.field_breed_time_value) FROM {field_data_field_breed_time} field ORDER BY field.field_breed_time_value DESC');
          
// adjust this to match your DB table and field name for the HMS field
   
foreach ($result1 as $row1) {
     
$options1[$row1->field_breed_time_value] = _hms_seconds_to_formatted($row1->field_breed_time_value, 'h:mm:ss', TRUE);
           
// adjust to field names from query - the array keys will be in seconds as required for the search but will be formatted in a human friendly way in the dropdown
            // you can adjust your formatting here, pick 'h:mm' instead of 'h:mm:ss'.  The last parameter is TRUE or FALSE depending on leading zero.
   
}
   
$options1[''] = '<Any>';
       
// this adds an option to filter for all values.
   
$form['time']['#type'] = 'select';
   
$form['time']['#options'] = $options1;
   
$form['time']['#multiple'] = FALSE;
   
$form['time']['#attributes'] = array (
     
'size' => 1,
    );
  }
}
?>

I hope you find this helpful!

-Daniel
Dragonvale Breeding Guide

Category:bug» feature
Status:Active» Fixed

See release 7.x-1.2 https://drupal.org/node/2047187

Status:Fixed» Closed (fixed)

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

Status:Closed (fixed)» Active

Thanks for fixing this! However, when exposing the operand, there are three fields that always display regardless of which operand I choose: Value, Min and Max. That is a bit confusing since if I choose "Is Between", then I need to use the latter two fields, whereas if I choose something like "Is Less Than", I must enter the one value in the first field but leave the other two.

Is this different from other numeric fields (other integer fields) in Views?
The only difference with the integer field is that the display and input is different; the code from the integer field is inherited.