You are here

function _hms_factor_map in HMS Field 7

Returns the factor map of the format options.

Note: We cannot go further then weeks in this setup. A month implies that we know how many seconds a month is. Problem here is that a month can be 28(29), 30 or 31 days. Same goes for C (century) Y (year) Q (quarter). Only solution is that we have a value relative to a date.

Use HOOK_hms_factor_alter($factors) to do your own magic.

7 calls to _hms_factor_map()
hms_field_field_formatter_settings_form in ./hms_field.module
Implements hook_field_formatter_settings_form().
hms_field_field_formatter_settings_summary in ./hms_field.module
Implements hook_field_formatter_settings_summary().
theme_hms_natural_language in ./hms_field.module
Theme hms_natural_language
_hms_add_running_js in ./hms_field.module
Add js for running HMS fields.
_hms_formatted_to_seconds in ./hms_field.module
Returns number of seconds from a formatted string.

... See full list

File

./hms_field.module, line 406
Provides an hms_field functionality.

Code

function _hms_factor_map($return_full = FALSE) {
  $factor = drupal_static(__FUNCTION__);
  if (empty($factor)) {
    $factor = array(
      'w' => array(
        'factor value' => 604800,
        'label single' => t('week'),
        'label multiple' => t('weeks'),
      ),
      'd' => array(
        'factor value' => 86400,
        'label single' => t('day'),
        'label multiple' => t('days'),
      ),
      'h' => array(
        'factor value' => 3600,
        'label single' => t('hour'),
        'label multiple' => t('hours'),
      ),
      'm' => array(
        'factor value' => 60,
        'label single' => t('minute'),
        'label multiple' => t('minutes'),
      ),
      's' => array(
        'factor value' => 1,
        'label single' => t('second'),
        'label multiple' => t('seconds'),
      ),
    );
    drupal_alter('hms_factor', $factor);
  }
  if ($return_full) {
    return $factor;
  }

  // We only return the factor value here.
  // for historical reasons we also check if value is an array.
  $return = array();
  foreach ($factor as $key => $val) {
    $value = is_array($val) ? $val['factor value'] : $val;
    $return[$key] = $value;
  }
  return $return;
}