Units API
raspberryman - January 5, 2009 - 21:07
Units API converts between various weights and measurements.
The central API call, unitsapi_convert($value, $from, $to, $details = FALSE), uses the International System of Units (SI) conversion factors to convert measurement units.
This module is only an API and does not have an user interface.
SUPPORTED UNITS
A list of supported units, and the keys you need to pass to the unitsapi_convert() function, are available on the module's help page.
EXAMPLES
<?php
// Convert kilometer to feet
$result = unitsapi_convert(1.5, 'kilometer', 'foot');
// $result == 4921.259843
// Convert Fahrenheit to Kelvin
$result = unitsapi_convert(55, 'fahrenheit', 'kelvin');
// $result == 285.927778
// Convert US liquid ounces to Imperial pints with a detailed array of the conversion
$result = unitsapi_convert(50, 'us fluid ounce', 'imperial pint', TRUE);
// $result == Array ([result] => 2.602107, [from] => US fluid ounces, [to] => Imperial pints)
?>HOOK_UNITSAPI($data)
Use hook_unitsapi($data) to make changes to the units array. For example:
<?php
/**
* Implementation of hook_unitsapi().
*/
function mymodule_unitsapi() {
$data['meter']['singular'] = 'metre';
return $data;
}
?>FUTURE PLANS
- Add additional measurement units
- Add additional automated tests
SPONSORED BY
This module is sponsored by Raspberry Man LLC (http://www.raspberryman.com)
Releases
| Official releases | Date | Size | Links | Status | |
|---|---|---|---|---|---|
| 6.x-1.0-alpha1 | 2009-Feb-28 | 12.59 KB | Download · Release notes | Recommended for 6.x | |
| Development snapshots | Date | Size | Links | Status | |
|---|---|---|---|---|---|
| 6.x-1.x-dev | 2009-Feb-28 | 12.59 KB | Download · Release notes | Development snapshot | |
