unitsofmeasurement / indriya

JSR 385 - Reference Implementation
Other
119 stars 42 forks source link

Missing symbol for some derived units #409

Closed J-N-K closed 1 month ago

J-N-K commented 9 months ago

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.

keilw commented 9 months ago

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 commented 9 months ago

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.