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

  1. Add additional measurement units
  2. Add additional automated tests

SPONSORED BY

This module is sponsored by Raspberry Man LLC (http://www.raspberryman.com)

Releases

Official releasesDateSizeLinksStatus
6.x-1.0-alpha12009-Feb-2812.59 KBRecommended for 6.xThis is currently the recommended release for 6.x.
Development snapshotsDateSizeLinksStatus
6.x-1.x-dev2009-Feb-2812.59 KBDevelopment snapshotDevelopment snapshots are automatically regenerated and their contents can frequently change, so they are not recommended for production use.


 
 

Drupal is a registered trademark of Dries Buytaert.