Skip to content
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

SimpleUnitFormat.parse() does not always work with prefixes #343

Open
keilw opened this issue Apr 17, 2021 · 2 comments
Open

SimpleUnitFormat.parse() does not always work with prefixes #343

keilw opened this issue Apr 17, 2021 · 2 comments

Comments

@keilw
Copy link
Member

keilw commented Apr 17, 2021

There are at least one or two cases where SimpleUnitFormat.parse() (or AbstractUnit.parse()) won't recognize a string that can be properly formatted, it seems related to prefixes where observed.

E.g. AbstractUnit.parse("dm") works just the same way as DECI(METRE).toString(), but the result of
DECI(CARAT).toString() fails parsing it with AbstractUnit.parse("dct").
Note CARAT is defined by the extension module Unicode CLDR, but it should not really matter if the unit is defined by the RI itself or an extension.

@keilw keilw changed the title SimpleUnitFormat.parse() sometimes does not work with prefixes SimpleUnitFormat.parse() does not always work with prefixes Apr 17, 2021
@keilw keilw added this to the 2.1.3 milestone Apr 20, 2021
@keilw keilw removed this from the 2.1.3 milestone May 21, 2021
@cmmercer
Copy link

cmmercer commented Dec 8, 2021

I have also encountered this when using a custom unit (of geologic time, the "annus" with symbol "a") that I defined in my own SystemOfUnits. I took care to register a label with SimpleUnitFormat, so I can parse it when the unit does not have a prefix. But when I instantiate the unit with a metric prefix and try to parse the result of calling toString() (e.g., "Ma" or "ka") it fails.

@keilw keilw modified the milestone: 2.2.4 Feb 7, 2025
@keilw
Copy link
Member Author

keilw commented Feb 7, 2025

I know, this one has been around for some time. For certain units, they are not even meant to work with prefixes, see #433.
We faced that problem trying to support all prefixes for units like YEAR (also using the symbol "a") and PETA(YEAR) would then result in "Pa" which is also the standard symbol for PASCAL.

We could in a future version (probably not before 2.2.4 or later) consider making aliasWithPrefixes() and labelWithPrefixes() both currently private to the default subclass of SimpleUnitFormat public, similar to removeAlias() or removeLabel(). Both of which may be used to clean or change a custom prefix definitionlike the ones mentioned.

I think we should discuss this a bit further in the discussion forum before making those methods visible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants