indriya icon indicating copy to clipboard operation
indriya copied to clipboard

Missing symbol for some derived units

Open J-N-K opened this issue 1 year ago • 2 comments

In https://github.com/openhab/openhab-core/issues/3962 we found that d works as unit for days, but y does not work for years. The same applied to mo and wk.

I believe the difference is that DAY is defined as a TransformedUnit and added directly by INSTANCE.units.add(unit) while YEAR is added via AbstractSystemOfUnits.Helper.addUnit(Set<Unit<?>> units, U unit, String name, String symbol). It seems in the latter case the symbol is not made available as alias for parsing.

J-N-K avatar Dec 26 '23 18:12 J-N-K

Unlike DAY or HOUR, YEAR and WEEK are added to the unit system differently. Which persists the name and symbol, but does not also label them. It is not so trivial, but should be doable, e.g. by adding another style that takes name, symbol and label into consideration.

keilw avatar Jan 05 '24 11:01 keilw

Thanks for pointing this out. There are a couple of tweaks in SimpleUnitFormat. I added an alias, e.g. "wk" to "week", but kept the label based on https://www.btb.termiumplus.gc.ca/tcdnstyl-chap?lang=eng&lettr=chapsect1&info0=1.23, Does this work for you, or would you expect "wk" to be the label/toString representation?

Because other sources like convertunits.com/info/weeks list it as the symbol, but Wikipedia also prints out "week" in most cases.

keilw avatar Jan 07 '24 14:01 keilw