Version 27 by Gavin
on Nov 06, 2006 21:07.

compared with
Current by Thomas Weidner
on Jan 25, 2007 13:21.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (28)

View Page History
<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFDEV:Zend Proposal Zone Template}

{zone-data:component-name}

{zone-data:revision}
4.0 - 25 Jan 2007: API rework, simpler useage
3.1 - 23 July 2006: Corrections based on actual work
3.0 - 18 July 2006: Class redesign based on actual work and comments from Zend

{zone-data:use-cases}
Get output of Celsius Kelvin in actual locale
{code}
$unit = new Zend_Measure_Temperature('23,643°');
echo $unit;
// returns 23,643°CK when en_EN is standard locale
{code}

Get formatted output in different locale
{code}
$unit = new Zend_Measure_Temperature('23,643', Zend_Measure_Temperature::FAHRENHEIT, Zend_Locale::de_DE); 'de_DE');
echo $unit->toString();
// returns 23,643°F as de_DE is set (',' instead of '.')
Different Input Types which would be recognized
{code}
$input = new Zend_Measure('0',Zend_Measure::LENGTH); Zend_Measure_Length('0',Zend_Measure_Length::STANDARD); // = 0 meter
$input = new Zend_Measure_Length('123456',Zend_Measure_Length::KILOMETER); // = 123456000 meter
$input = new Zend_Measure_Length('123456','KILOMETER'); // = 123456000 meter
$input = new Zend_Measure('123,456',Zend_Measure::LENGTH); Zend_Measure_Length('123,456',Zend_Measure_Length::STANDARD); // = 123456 meter
$input = new Zend_Measure('123,456.7890',Zend_Measure::LENGTH); Zend_Measure_Length('123,456.7890',Zend_Measure_Length::STANDARD); // = 123456.7890 meter
$input = new Zend_Measure_Temperature('the earth is 14,350.5 kilometer and it has 24°',Zend_Measure::TEMPERATURE); 24°',Zend_Measure_Temperature::STANDARD);
// this would return 14350.5 celsius, as only the first number will be parsed
$input = new Zend_Measure_Length('Die Sonne hat 14.350,5 km breite', Zend_Measure_Length::KILOMETER,Zend_Locale::de_DE); Zend_Measure_Length::KILOMETER,'de_DE');
// value would be 14350500 meter as in german the group seperation is '.' and not ',' as in english
$input = new Zend_Measure_Length('14.350,6',Zend_Measure_Length::KILOMETER);
// value would be 14350 meter when standard locale is en
// but it would be 14350600 meter when the standard locale is de
Convert Fahrenheit to Celsius
{code}
$unit = new Zend_Measure_Temperature('86,7°F',Zend_Measure_Temperature::FAHRENHEIT); // measurement unit value is 86.7
echo $unit->convert(Zend_Measure_Temperature::CELSIUS);
// output 23,7°C
Convert Kilo to Tonne with other locale
{code}
$unit = new Zend_Measure_Weight('25742.54 kg',Zend_Measure_Weight::KILOGRAM);
echo $unit->convert(Zend_Measure_Weight::TONNE,Zend_Locale::de_DE); $unit->convert(Zend_Measure_Weight::TONNE,'de_DE');
// outputs 25,74T
{code}
Maths with different units
{code}
$unit = new Zend_Measure_Weight('23.5kg', Zend_Measure_Weight::KILOGRAM);
$second = new Zend_Measure_Weight('10pd', Zend_Measure_Weight::POUND);
echo $unit->add($second);
// outputs 28.03kg
class Zend_Measure_Exception extends Zend_Exception {}

class Zend_Measure implements Serializable {

// actual measurement object
protected $_measurement;

const LENGTH = Zend_Measure_Length::STANDARD;
const TEMPERATURE = Zend_Measure_Temperature::STANDARD;

/**
* Constructor
*
* @param $value mixed - can be integer, real or string
* @param $type - OPTIONAL type of unit (length, area, temperature, ...), when not defined
* the standard type for this measurement type would be taken (Length->METER, Temperature->CELSIUS,...)
* @param $locale - OPTIONAL locale, when not defined the standard locale would be taken
*/
public function __construct($value, $type, $locale) {}

/**
* Serialization Interface
*/
public function serialize() {}
public function unserialize() {}

/**
* Converts the standard unit to the expected unit
* Alias for toString($type, OPTIONAL, OPTIONAL)
*
* @param $type
* @param $locale - OPTIONAL locale for output
* @param $format - OPTIONAL format for output
* @return string
*/
public function convert($type, $locale, $format) {}

/**
* Returns a plain value
*
* @param $type - OPTIONAL other type
* @return mixed (integer or float)
*/
public function toValue($type)
/**
* Returns the locale formatted unit string (f.e. 1,234.567)
*
* @param $type - OPTIONAL other type for output
* @param $locale - OPTIONAL other locale for output (f.e. output in german locale 1.234,567)
* @param $format - OPTIONAL other format for output (f.e. for rounding with precicion of 2 1,234,57)
* @return string
*/
public function toString($type, $locale, $format);
public function __toString($type, $locale, $format);

/**
* Adds a unit to an other
*
* @param $unit mixed - unit object
* @return unit - return the new unit
*/
public function add($unit) {}

/**
* Substracts a unit from an other
*
* @param $unit mixed - unit object
* @return unit - return the new unit
*/
public function sub($unit) {}

/**
* Compares two units, returning the difference
*
* @param $unit mixed - unit object
* @return unit - return the new unit
*/
public function compare($unit) {}
}

/**
* Definition for all Types
* One Class per Type
*/
class Zend_Measure_Length extends Zend_Measure_Abstract
{

/**
* Returns the locale formatted unit string (f.e. 1,234.567)
* Returns a string representation
* @param $type - OPTIONAL other type for output
* @param $locale - OPTIONAL other locale for output (f.e. output in german locale 1.234,567)
* @param $format - OPTIONAL other format for output (f.e. for rounding with precicion of 2 1,234,57)
* @return string
*/
public function toString() {}
public function __toString() {}

/**
* Converts the standard unit to the expected unit
* Alias for toString($type, OPTIONAL, OPTIONAL)
*
* @param $type
* @param $locale - OPTIONAL locale for output
* @param $format - OPTIONAL format for output
* @return string
*/
public function convert($type, $locale, $format) {}

/**
* Returns a plain value
*
* @param $type - OPTIONAL other type
* @return mixed (integer or float)
*/
public function toValue($type)

/**
* Adds a unit to an other
*
* @param $unit mixed - unit object
* @return unit - return the new unit
*/
public function add($unit) {}

/**
* Substracts a unit from an other
*
* @param $unit mixed - unit object
* @return unit - return the new unit
*/
public function sub($unit) {}

/**
* Compares two units, returning the difference
*
* @param $unit mixed - unit object
* @return unit - return the new unit
*/
public function compare($unit) {}
}

class Zend_Measure_Power extends Zend_Measure_Abstract {}
class Zend_Measure_Circular extends Zend_Measure_Abstract {}
// and maybe some other types which I didn't wrote until now
// and other types

/**
{zone-data}

{zone-template-instance}
{zone-template-instance}]]></ac:plain-text-body></ac:macro>