-
Notifications
You must be signed in to change notification settings - Fork 14
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
Adding some additional units seems to break some conversions #41
Comments
Thanks for the report, it's greatly appreciated. I'm sorry for the inconvenience, it shouldn't be this way. I'll work on this over the weekend and get additional units back on a solid footing. It's not immediately clear why there are test interdependencies like the ones you are showing. |
Not forgotten, and apologies for the slow resolution to this. I'm still perplexed. I'm going to ship a new release today but it only focuses on fixing Elixir 1.16 compiler warning and does not resolve this bug. I didn't want to get your hopes up (just yet). |
I'm uncertain if this is related, but under # config/config.exs
config :ex_cldr_units, :additional_units,
inches_h2o: [
base_unit: :kilogram_per_meter_square_second,
factor: 248.84,
offset: 0,
sort_before: :all
] # test/app/services/conversions_test.exs
defmodule App.ConversionsTest do
use ExUnit.Case
alias App.Conversions
describe ".for_storage" do
test "converts passed values to a storage-appropriate unit" do
assert Conversions.Unit.new!(:inches_h2o, 10.212)
|> Conversions.Unit.convert!(:inches_h2o)
|> Conversions.Unit.value() == 10.212
end
end
end
I didn't open this as its own issue, because it seems to fit into the general category of "custom unit conversions not working as expected". It seems like some aggressive value transformation is happening behind the scenes, which in my case is resulting in the custom unit definition breaking on conversion attempts. The key difference in my case is that my |
I believe there is an implementation of factor with a numerator and denominator, which could meet your needs. But I don't think it would work still with this bug, it might just be an issue of the units I am converting around however. I think Example here: https://github.com/elixir-cldr/cldr_units/blob/main/config/test.exs#L25 |
@kerrd89: thanks; the fractional factor implementation does indeed work for my case. My concerns are the following:
I raised my case in this issue in the hopes that it might help pinpoint the changes that are causing the problem you're encountering, as well. |
Sorry for the very long delay in working this more deeply. I've finally finished the fairly major refactor I needed to do (common factor reduction in canonical base name calculation). Now I can focus on open issue here with the objective to have the work done in time for the April release cycle that coincides with CLDR 45. |
Hi, I just wanted to add to this issue. I've also added additional units (duration, in my case). They simply failed to work until I read in a forum (https://elixirforum.com/t/how-to-add-custom-measurement-units-with-cldr-unit-additional/58430/4) that ex_cldr_units 3.16.3 fixed this problem. So, I now have the latest release, 3.16.4, installed and the additional units are recognised. The trouble is that I now see this terrible conversion problem, converting from minutes to hours:
As you can see, there are two problems here: the conversion is very wrong, and even for simple common denominators, there is always a recurring digit, which is likely to result in incorrect rounding errors, in my case when the time comes to calculate invoicable amounts. Some more examples:
I have tried to comment out my additional units and recompile to check whether I can get back to normal behaviour, but it didn't work as my additional units are still recognised, and all the calculations are off as in the examples above. Please let me know if there's any further testing I can perform to help. |
This may be an issue with my poor understanding. But I was able to break tests tests in the
cldr_units
library by passing some:additional_units
which I believe should be acceptable, based on the documentation.updating
config/test.exs
to add a decatherm w/ a base_unit of :therm_usThese changes do successfully implement a conversion for :therm_us to :dtherm_us (and likewise)
These changes cause these failures. It also breaks the conversion of 1
therm_us
tokillowatt_hour
Apologies if this is user error. I am happy to update documentation to prevent any future confusion, if this is a me problem.
Thank you in advance for your time!
The text was updated successfully, but these errors were encountered: