Comments (4)
I'm not sure what you mean, what change to the constructor signature are you proposing? The interface for instantiating the object in your example seems the same as the current constructor; am I missing something?
Regardless, as far as the proposed change to allow for multiple conversions at once, I disagree that there's a need for it. How is it any better than:
$area = new Area(1000200.000304, 'm^2');
$actual = array();
foreach (array('km^2', 'm^2', 'cm^2', 'mm^2') as $to_unit ) {
$actual[$to_unit] = $area->toUnit($to_unit);
}
Moving this sort of behavior into a library doesn't really gain any additional utility, and it adds costs in terms of library complexity and obscure interfaces.
I'd rather keep this library as straightforward as possible, unless there's a compelling need to add additional behavior. Does that make sense?
from php-units-of-measure.
Hi, it doesn't work like that because we don't have function to get modulation yet.
In my case 1.5 km should return as 1km + 500m (something like these) or 1.1 ft may return in 1 ft + 1/12 inches. or Time 86700 secs may return as 1 day + 5 minutes or 5100mg may return as 5g + 100 mg.
For my real usage (sorry, for example about Thai area unit), we use Rai (equals to 400 sq.m.) Ngan (equals to 100 sq.m.) and Sq.Wa (4 sq.m).
We don't say 401 sq.m. , we don't say 100.25 Sq. Wa. but we say 1 Rai + 0.25 Sq. Wa.
something like that.
I'm missing one part, in previously, I have put the fraction part as here
https://github.com/scalopus/php-units-of-measure/blob/master/source/PhpUnitsOfMeasure/UnitOfMeasure.php#L53
but your repository just merged #9 in the master here.
https://github.com/triplepoint/php-units-of-measure/blob/master/source/PhpUnitsOfMeasure/UnitOfMeasure.php#L53
so, I just think that it would be too long and complicate to method to add some more option to the constructor.
What I proposed is that may use something like
new UnitOfMeasure(array(
'from_native_unit ' => .....,
'to_native_unit' => ......,
'alias' => ......,
'fraction' => ......,
'translator' => .....,
etc...
));
because the multiple unit may not have to implement in all UnitOfMeasure (Like Temperature), so, I think that to make it as above, it will be like optional.
let me know if this kind of feature should be in this library.
from php-units-of-measure.
Actually I'm proposing more than this.
We can actually put all these into a definitions file and a loader will load the configuration. (maybe we can use packfire/config
)
The units are not defined in the code, but in the definitions file.
from php-units-of-measure.
Ah, I'm sorry Scalopus, I misunderstood your first example. I see now what you're getting at.
It's a neat idea, but I think it's beyond the complexity limit that I'm willing to entertain for this project. I'd encourage you to explore this idea in a separate library, maybe using this one internally to do some of the conversions?
from php-units-of-measure.
Related Issues (20)
- Use bc math HOT 5
- Piece Measure Unit HOT 2
- Is it possible to get all supported units? HOT 4
- Static create method HOT 6
- php-units-of-measure should replace triplepoint HOT 3
- Missing translations HOT 2
- List or verify if a unit exist in a given implementation HOT 6
- Error in AbstractPhysicalQuantityTest::getTestUnitOfMeasure HOT 3
- Add support for Power HOT 2
- Add support for Population HOT 2
- [PhysicalQuantity] Add support for Viscosity (code provided)
- Making `static::unitNameOfAliasesAlreadyRegistered` optional depending on environment
- Add support for Torque Units
- How to get original unit? HOT 3
- Tag latest commits with a new version HOT 1
- Converting cm to feet / inches? HOT 1
- Use Brick/Math
- Get class for unit
- Awareness of Units Summit Summer 2022 HOT 1
- Does this project uses the UCUM system? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-units-of-measure.