You are here

function recipe_duration_iso8601 in Recipe 8.2

Same name and namespace in other branches
  1. 7.2 recipe.module \recipe_duration_iso8601()
  2. 7 recipe.module \recipe_duration_iso8601()

Returns a duration string in ISO 8601 format.

Parameters

$duration: An integer or array with 'value' element representing a time duration.

Return value

string A string representing a time duration in ISO 8601 format.

2 string references to 'recipe_duration_iso8601'
rdf.mapping.node.recipe.yml in config/install/rdf.mapping.node.recipe.yml
config/install/rdf.mapping.node.recipe.yml
template_preprocess_recipe_total_time in ./recipe.module
Prepares variables for the recipe_total_time template.

File

./recipe.module, line 309
Contains functions for Recipe node CRUD and display.

Code

function recipe_duration_iso8601($duration = 0) {
  if (is_array($duration) && isset($duration['value'])) {
    $duration = $duration['value'];
  }
  $hours = floor($duration / 60);
  $minutes = $duration % 60;
  $output = '';
  if ($hours > 0) {
    $output .= $hours . 'H';
  }
  if ($minutes > 0) {
    $output .= $minutes . 'M';
  }
  return empty($output) ? 'PT0M' : 'PT' . $output;
}