views_handler_field_time_interval.inc

Definition of views_handler_field_time_interval.

File

handlers/views_handler_field_time_interval.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_field_time_interval.
  5. */
  6. /**
  7. * A handler to provide proper displays for time intervals.
  8. *
  9. * @ingroup views_field_handlers
  10. */
  11. class views_handler_field_time_interval extends views_handler_field {
  12. function option_definition() {
  13. $options = parent::option_definition();
  14. $options['granularity'] = array('default' => 2);
  15. return $options;
  16. }
  17. function options_form(&$form, &$form_state) {
  18. parent::options_form($form, $form_state);
  19. $form['granularity'] = array(
  20. '#type' => 'textfield',
  21. '#title' => t('Granularity'),
  22. '#description' => t('How many different units to display in the string.'),
  23. '#default_value' => $this->options['granularity'],
  24. );
  25. }
  26. function render($values) {
  27. $value = $values->{$this->field_alias};
  28. return format_interval($value, isset($this->options['granularity']) ? $this->options['granularity'] : 2);
  29. }
  30. }