geniusgeeek/pu-converter

PU-converter is a simple and an easy to use PHP unit converter library for converting mathematical, engineering and scientific units

1.0.2 2021-07-24 18:37 UTC

This package is auto-updated.

Last update: 2024-04-29 05:05:28 UTC


README

License build status

PU-converter

PU-converter is an easy to use PHP unit converter library for converting S.I units to other compatible unit types. With PU-converter you can easily convert any engineering unit to its different unit types, for example, kilogram to grams, celsius to kelvin, e.t.c. Save your self the math stress and let the PU-converter library handle all conversions for you.

Coverage

PU-converter allows you to convert any unit to any other compatible unit type.

It has no external dependencies, simply include the library in your project and you're set

PU-converter can handle a wide range of unit types including:

  • Length
  • Area
  • Volume
  • Mass
  • Speed
  • Temperature
  • Pressure
  • Time
  • Energy/Power
  • Disk Storage
  • Frequency
  • Plane Angles

Installation

Using Composer

PU-converter can be insatlled using composer

composer require geniusgeeek/pu-converter

without composer

To utilize this class, first import puconverter.php into your project, and instantiate it.

include '/path/to/puconverter.php';
use  unitConverter\puconverter\PUconverter;

Guidelines: How to use

  1. Create an object of the class for conversion
  2. The object propeties should be initialised on object creation
  3. Parameter 1 is the class for conversion, Parameter 2 is the value to be converted, Parameter 3 is the unit to convert, Parameter 4 is the unit to be converted to
  4. To return the conversion call the method convert()
  5. All units are to be passed in their SI units/abbreviations, example: kilogram is kg, seconds is s, e.t.c.

Documentation

Create an object for different conversion class using the syntax below

  1. $temperature => new PUconverter("temperature", $value, $fromUnit, $toUnit);
  2. Area => new PUconverter("area", $value, $fromUnit, $toUnit);
  3. Plane Angles => new PUconverter("angle", $value, $fromUnit, $toUnit);
  4. Time => new PUconverter("time", $value, $fromUnit, $toUnit);
  5. Volume => new PUconverter("volume", $value, $fromUnit, $toUnit);
  6. Speed => new PUconverter("speed", $value, $fromUnit, $toUnit);
  7. Length => new PUconverter("length", $value, $fromUnit, $toUnit);
  8. Pressure => new PUconverter("pressure", $value, $fromUnit, $toUnit);
  9. Mass => new PUconverter("mass", $value, $fromUnit, $toUnit);
  10. Frequency => new PUconverter("frequency", $value, $fromUnit, $toUnit);
  11. Energy/Power => new PUconverter("energy", $value, $fromUnit, $toUnit);
  12. Disk Storage => new PUconverter("storage", $value, $fromUnit, $toUnit);

Simple Examples

use  unitConverter\puconverter\PUconverter;
$length = new PUconverter("length", 3000, 'km', 'm');
echo $length->convert(); //this converts 3000 kilometers to its equivalent meter

//Returns 3000000 meters

use  unitConverter\puconverter\PUconverter;
$time = new PUconverter("time", 1, 'yr', 'week');
echo $time->convert(); // this converts 1 year to its equivalent time in weeks

//returns 52.143 weeks

Valid Units

Temperature
k => Kelvin
c => celsius
f => fahrenheit

Area
m2 => Square Meter
km2 => Square Kilometer
cm2 => Square Centimeter
mm2 => Square Millimeter
ft2 => Square Foot
mi2 => Square Mile
ac => Acre
ha => hectare

Volume
l => Litre
ml => Millilitre
m3 => Cubic Meter
gal => Gallon
oz => fluid ounces
ft3 => cubic feet
cm3 => cubic centi meter

Mass
kg => Kilogram
g => Gram
mg => Milligram
lb => Pound
t => Tonne

Speed
mps => Meters per Second
kph => Kilometers Per Hour
mph => Miles Per Hour
knots => Knots

Planes Angles
deg => Degrees
rad => Radian
grad => gradian

Pressure
pa => Pascal
kpa => kilopascal
mpa => MegaPascal
bar => Bar
mbar => Millibar
psi => Pound-force per square inch

Time
s => Second
yr => Year
month => Month
week => Week
day => Day
hr => Hour
min => Minute
ms => Millisecond
dec => decade
cen => century

Energy/Power
j => Joule
kj => Kilojoule
gcal => Gram calorie
whr => Watt Hour
kwhr => Kilowatt Hour
ev => Electronvolt
kcal => kilocalorie

Disk Storage
bit => bit
byte => byte
kb => kilobyte
mb => megabyte
gb => gigabyte
tb => terabyte
pb => petabyte

Frequency
hz => hertz
khz => kilo hertz
mhz => mega hertz
ghz => giga hertz

Length
m - Meter
km - Kilometer
cm - Centimeter
mm - Millimeter
um - Micrometer
nm - Nanometer
in - Inch
ft - Foot
yd - Yard
mi - Mile

Author

Initial work- Gracious Emmanuel

Contributors

Ordago: https://github.com/ordago

Contributing

Please, read the contributing.md to see contributing process, code of conduct and pull request process.