-
-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support interoperability to other unit systems #402
Comments
I tried to create separate system using only EURO.toString() // Prints "€"
EURO.divide(Units.MEGAWATT_HOUR).toString() // Prints "null/MWh" How can I register my Euro unit to I'm out of ideas. I try to use UoM in openHAB, but in this case it seems impossible to tell the unit for the system. Sadly I have to fall back use only BigDecimals. |
Now I found the way to introduce my units using |
Yes, that's indeed the way. Note, in the most recent Indriya versions, there is For |
I don't know what EBNF means 😕 Now i faced minor issue. Let's say that |
I was thinking of a "hybrid" between this JSR and JSR 354 (Money and Currency) for quite a while, but it is a bit complicated.
|
Hello,
It is feasible (ref. Money) but currency exchange is not symmetrical (EUR
=> USD is not the same as USD => EUR), in other words how you convert is
important (exchange rate is a tuple).
Cheers,
Jean-Marie
Le mer. 6 déc. 2023 à 20:18, Werner Keil ***@***.***> a
écrit :
… I was thinking of a "hybrid" between this JSR and JSR 354 (Money and
Currency) for quite a while, but it is a bit complicated.
@dautelle <https://github.com/dautelle> had a money implementation back
in the days of JSR 275.
BaseUnit should not be extended because it meets a very special purpose,
the SI base units, nothing else.
Not sure, why you would use Dimension for currencies, aren't those units?
You might have to play a bit with the label() method of SimpleUnitFormat,
but that way USD and AUD could have distinct names but the same label
("$")
—
Reply to this email directly, view it on GitHub
<#402 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABPH2KVEZPNOHGCVZ72KXVDYIDAJTAVCNFSM6AAAAAA4WXIZEOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBTGU2DIMJYGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I'm working on a similar problem (openhab/openhab-core#3503). While conversion of currencies (we use symmetrical only, but the issue is similar) works fine, product units (like The reason is that
because it has a fixed set of supported converters and it is not possible to add new converters. The set of converters is retrieved from For us using a |
Thanks for mentioning this. I suppose, you do have some sort of The |
Correct, it's a sub-class of What I'm doing now is adding it via reflection (with order 1000), but that is of course a dirty hack. |
@keilw: I added currency "¤" dimension, because I don't understand the dimension system and don't want to mess with existing ones. $ symbol isn't problem for me for now. I use ISO code for parsing using alias. And currencies are shown using symbols. The user knows the context. @dautelle: I don't need to exchange currencies. I only want to convert units eg. 100 €/MWh => 10 snt/kWh. That's easy divide by ten without the units library, but I have fetish to use it 😄
@keilw, @J-N-K: I don't understand what are the benefits of closing every single class in the implementation if they aren't the public API. Developers can always fork codes and patch them (like I often do). But that causes that I can't integrate my implementation to OpenHAB. Currently my UoM works as I like inside the binding, but OpenHAB doesn't understand those units. So I use full Quantities inside of the binding and tell only numbers (without units) to OpenHAB.
@keilw: I really understand if there is good reasons to close something. But then you should document those (in the code) and tell what is the correct way to do things or provide some workaround (in documentation). Sorry but I got a little pissed of this library. I didn't got it working in three weeks, so I give up, let it be and done thing the other way. |
I would like to ensure that one thing is 100% clear: The statement of @jpink is in no way endorsed by openHAB maintainers group and does not reflect my or any other opinion I know of. |
Thanks for the clarification. The beauty of open standards is, there are multiple implementations, if @jpink prefers to write his own, or use another one, sure no problem. |
In a broader sense having units for money with different currencies (USD, EUR, ...) falls in the same ballpark as having units like RADIAN and DEGREE. All those units have same dimensions (dimensionless in that case) but cannot necessarily be converted into one another. (I believe you cannot convert RADIAN into USD, or RADIAN int STERADIAN.) We say those units are not commensurable. However having categories of units that form a set of commensurable units, would be nice. E.g. having a set of units for the category money that allows for converters to be defined within this category. Not sure if the current API can do this or if it can be extended to do this. I don't have immediate answers. Perhaps I find time later this month. Some related material:
|
The use case of OpenHAB is mainly something like |
@andi-huber: I agree that there will be challenges to convert many different kinds of dimensionless units. But I think this library wasn't birth because of ideological or theoretical reasons. It should solve real world problems and there is no need to try convert radians to USD. |
My target is to create "custom" units for electricity prices: €/MWh and c/kWh. I added following classes:
When i try to print quantity i get error:
That is because my class isn't
AlternateUnit
orProductUnit
.I'm not planning to do currency exchanges (although its possible use some service). Just playing on same currency and combining to SI system.
The text was updated successfully, but these errors were encountered: