function units_converters_temperature in Units of Measurement 7
Units convert callback for temperature measures.
Convert temperature between different units of measurement.
Parameters
float $value: Value in $from units that should be converted into $to units
Entity $from: Units entity in which $value is represented
Entity $to: Units entity into which $value should be converted
Return value
float $value converted into $to units
1 string reference to 'units_converters_temperature'
- temperature.inc in plugins/
converters/ temperature.inc
File
- plugins/
converters/ temperature.inc, line 29
Code
function units_converters_temperature($value, $from, $to) {
$case = $from->machine_name . '_' . $to->machine_name;
switch ($case) {
case 'celsius_fahrenheit':
return $value * (9 / 5) + 32;
break;
case 'celsius_kelvin':
return $value + 273.15;
break;
case 'fahrenheit_kelvin':
return ($value - 32) * (5 / 9) + 273.15;
break;
case 'fahrenheit_celsius':
return ($value - 32) * (5 / 9);
break;
case 'kelvin_fahrenheit':
return ($value - 273.15) * (9 / 5) + 32;
break;
case 'kelvin_celsius':
return $value - 273.15;
break;
}
// We are not supposed to fall through the switch above, so if we ever happen,
// then something is wrong and we return a negative result.
return FALSE;
}