unitsofmeasurement / indriya

JSR 385 - Reference Implementation
Other
115 stars 40 forks source link

Parsing of 1/mile is not possible #413

Open acimail01 opened 5 months ago

acimail01 commented 5 months ago
SimpleUnitFormat.getInstance().alias(USCustomary.MILE, "mile");
Quantity<?> q1 = ServiceProvider.current().getFormatService().getQuantityFormat().parse("3 km");
Quantity<?> q2 = ServiceProvider.current().getFormatService().getQuantityFormat().parse("3 mi");
Quantity<?> q3 = ServiceProvider.current().getFormatService().getQuantityFormat().parse("3 mile");
// Quantity<?> q4 = ServiceProvider.current().getFormatService().getQuantityFormat().parse("3 1/km"); // Exception
Quantity<?> q5 = ServiceProvider.current().getFormatService().getQuantityFormat("EBNF").parse("3 1/km");
// Quantity<?> q6 = ServiceProvider.current().getFormatService().getQuantityFormat("EBNF").parse("3 1/mi"); // Exception
// Quantity<?> q7 = ServiceProvider.current().getFormatService().getQuantityFormat("EBNF").parse("3 1/mile"); // Exception

Parsing of 1/km with Simple-Parser is not possible Parsing of 1/mile wirh EBNF-Parser is not possible

keilw commented 4 months ago

Could you please elaborate the use case for this?

Even in the UCUM Specification which is by far the most extensive catalog of units there is no definition of "1/km", "1/kg" or similar, meaning it would likely fail against UCUMFormat or UCUM's own test suites as well.