pdobrovolny/quantity

Physical quantities and formulas

1.0.0 2018-08-14 11:31 UTC

README

Latest Stable Version Total Downloads Latest Unstable Version License Monthly Downloads Daily Downloads composer.lock

pipeline status

coverage report

Donate to this project using Patreon

Quantity

Physical quantities and formulas

Documentation and usage

A library to represent various quantities as value objects with the ability to convert from one Unit of Measurement to another.

International System of Units

Base units

  • Amount of substance
  • Electric current
  • Length
  • Luminous intensity
  • Mass
  • Thermodynamic temperature
  • Time

Derived units

  • Angle
  • Area
  • Electric resistance
  • Force
  • Frequency
  • Pressure
  • Velocity
  • Voltage
  • Volume
  • Volumetric flow rate
  • Work

Sub-units

  • Angle
    • ArcMinute
    • ArcSecond
    • Degree
  • Length
    • Astronomical unit
    • Light year
    • Parsec
  • Mass
    • Atomic mass unit
    • Tonne
  • Time
    • Day
    • Hour
    • Minute
  • Celsius
  • Hectare
  • Liter
  • Optical power
  • Volt-ampere

Imperial units

  • Length
    • Chain
    • Foot
    • Furlong
    • Inch
    • League
    • Mile
    • Yard
  • Mass
    • Grain
    • Hundredweight
    • Ounce
    • Pound
    • Stone
    • Ton
  • Volume
    • Cubic Foot
    • Cubic Inch
    • Cubic Yard
  • Fahrenheit

Imperial units UK

  • Volume
    • FluidOunce
    • Gallon
    • Gill
    • Pint
    • Quart

Imperial units US

  • Volume
    • FluidOunce
    • Gallon
    • Gill
    • Pint
    • Quart

Examples

Main examples

Basic usage:

$length = Length::main(1.);

\var_dump($length->getMainValue());     // double(1)            Main scale of the unit
\var_dump($length->getUnit());          // string(1) "m"
\var_dump((string)$length);             // string(2) "1m"       (debug only)

Scaling (scalable units only):

$length = Length::centi(1.)->asMili();

\var_dump($length->getMainValue());     // double(0.01)         Main scale of the unit
\var_dump($length->getValue());         // double(10)           Selected scale value
\var_dump($length->getUnit());          // string(2) "mm"       Selected unit
\var_dump((string)$length);             // string(4) "10mm"

Converting examples

Mile to Length:

$mile = Mile::main(1.);
$length = $mile->toSILength();

\var_dump($mile->getMainValue());           // double(1)
\var_dump($length->getMainValue());         // double(1609.344)

Celsius to Fahrenheit:

$celsius    = Celsius::main(20.);
$fahrenheit = Fahrenheit::fromThermodynamicTemperature($celsius->toThermodynamicTemperature());

\var_dump($celsius->getMainValue());        // double(20)
\var_dump($fahrenheit->getMainValue());     // double(68)

Liter to Mass:

$volume = Liter::main(1.)->toVolume();

$massOfWater = $volume->toMass(Density::water());
\var_dump($massOfWater->getMainValue());            // double(0.998)

$massOfMercury = $volume->toMass(Density::mercury());
\var_dump($massOfMercury->getMainValue());          // double(13.57904)