pimlie / php-unit-conversion Goto Github PK
View Code? Open in Web Editor NEWA library providing full PSR-4 compatible unit conversions
License: MIT License
A library providing full PSR-4 compatible unit conversions
License: MIT License
Would need to add my custom units of measure. Like TonneKilimeter and PassengerKilometer in Length.
How can I do thats outside the scope of the library?
Something similar to Adding custom units, but only adding units to already defined units.
Am I missing something or there are no feet units for height?
Cheers
I'm dumb. It's foot lol
Is there anything to handle units of measurement for air pressure? Thank you!
I saw it is almost a year ago when the last release has been published. Since then the number of commits doubled. When will be the next release?
The SI unit for mass is kilogramm (kg) and not gramm (g).
For me it's okay that the package uses internally a different unit as base, but there should be an interface flagging units as SI if the base-unit isn't the SI unit.
foot to meters for the number 136043.25 gives back 124397.9478 instead the correct answer is 41465.9826.
$convertFromClass = "\PhpUnitConversion\Unit\Length\Foot';
$convertToClass = "\PhpUnitConversion\Unit\Length\Meter;
$convertFrom = new $convertFromClass($formatNumberToConvert);
$convertTo = new $convertToClass();
$convertedNum = $convertFrom->to($convertTo);
$convertValue = $convertedNum->format($precision, false); // debatable to use (float)
$convertNoPrecision = $convertedNum->getValue();
$convertSymbol = $convertedNum->getSymbol();
echo $convertValue; // It's wrong number
Right now it's not possible to add multiple single file units to the same unittype.
UnitMap::add('Unit1.php', '\\MyUnits', Length::class);
UnitMap::add('Unit2.php', '\\MyUnits', Length::class);
The problem is
php-unit-conversion/src/Map.php
Line 101 in a12cdb3
Instead of $array + $array
it should use array_merge_recursive()
. This will merge the arrays on the level they should get merged - the array of units in the unit-type.
The English word is spelled subtract (without an s), not substract as the library uses it.
Of course simply renaming it to the correct spelling would be a BC, but the incorrect version could be kept as an alias with a @deprecated
annotation.
E.g.
/* You can multiply a unit by calling `multiply` method with a float as an argument
* add always returns a new instance
*/
$quantity = 7;
$unitWeight = new Mass\Gram(500);
$totalWeight = $unitWeight->multiply($quantity);
echo $totalWeight->format(0);
// 3500 g
Hi im having a hard time figuring out why i get a not found.
I'm trying to add a Headcount.php unit within Amount unit type.
But i get this
Class 'PhpUnitConversion\Unit\Amount\HeadCount' not found
I'm using the UnitMap::add
UnitMap::add(
dirname(__DIR__, 2) .'/helpers/unitconversion/Fixtures/Amount/HeadCount.php',
"PhpUnitConversion\\Unit",
\PhpUnitConversion\Unit\Amount::class
);
First parameter is the server path that's the correct path to my HeadCount.php
Second im not sure what to use
Third the class of the unit type I want to add it to
This is my HeadCount.php unit
namespace PhpUnitConversion\Unit\Amount;
use PhpUnitConversion\Unit\Amount;
class HeadCount extends Amount
{
const FACTOR = 1;
const SYMBOL = 'hc';
const LABEL = 'head count';
}
Initlization:
$hd = new \PhpUnitConversion\Unit\Amount\HeadCount(343);
I need to initilize it like above reason i have dynamic way of calling it
$convertFromClass = "\PhpUnitConversion\Unit\\". $type . "\\" . $from;
$convertFrom = new $convertFromClass($formattedNumber);
Looking in Map.php source code the static load() adds it to self:$paths like this
"[["/var/www/vhost/biome/vendor/php-unit-conversion/php-unit-conversion/src/Unit/"
"PhpUnitConversion\Unit"
true
null]
["/var/www/vhost/biome/app/helpers/unitconversion/Fixtures/Amount/HeadCount.php"
"PhpUnitConversion\Unit"
true
"PhpUnitConversion\Unit\Amount"]]"
I've adjusted the registered units
UnitMap::clear();
UnitMap::add(Meter::class);
UnitMap::add(CentiMeter::class);
UnitMap::add(MilliMeter::class);
But now the nearest()
helper fails sometimes.
Length::nearest(1, Metric::class);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.