function commerce_license_duration_from_timestamp in Commerce License 7
Converts a unix timestamp to a duration with a unit (1 day, 2 weeks, etc).
Parameters
$timestamp: The unix timestamp to convert.
Return value
An array with the value as the first element, and the unit as the second.
2 calls to commerce_license_duration_from_timestamp()
- commerce_license_field_formatter_view in ./
commerce_license.module - Implements hook_field_formatter_view().
- commerce_license_field_widget_form in ./
commerce_license.module - Implements hook_field_widget_form().
File
- ./
commerce_license.module, line 1206 - Provides a framework for selling access to local or remote resources.
Code
function commerce_license_duration_from_timestamp($timestamp) {
if (!is_scalar($timestamp)) {
return array();
}
// Get the highest unit wholly contained in the value.
$unit = 60;
$units = commerce_license_duration_units();
foreach ($units as $multiplier => $label) {
if ($timestamp % $multiplier == 0) {
$unit = $multiplier;
break;
}
}
// Return the value and the unit.
return array(
$timestamp / $unit,
$unit,
);
}