mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
Fix month, week, day not supported (#3964)
Due to the way month, week and day are defined in Indriya their symbol is not added as alias. This is a bug in indriya, but their release cycles are quite long and we should provide a fix for our users. This should be backported to 4.1.x Signed-off-by: Jan N. Klug <github@klug.nrw>
This commit is contained in:
@@ -191,6 +191,7 @@ public final class Units extends CustomUnits {
|
||||
public static final Unit<Time> HOUR = addUnit(tech.units.indriya.unit.Units.HOUR);
|
||||
public static final Unit<Time> DAY = addUnit(tech.units.indriya.unit.Units.DAY);
|
||||
public static final Unit<Time> WEEK = addUnit(tech.units.indriya.unit.Units.WEEK);
|
||||
public static final Unit<Time> MONTH = addUnit(tech.units.indriya.unit.Units.MONTH);
|
||||
public static final Unit<Time> YEAR = addUnit(tech.units.indriya.unit.Units.YEAR);
|
||||
public static final Unit<VolumetricFlowRate> LITRE_PER_MINUTE = addUnit(new ProductUnit<VolumetricFlowRate>(
|
||||
tech.units.indriya.unit.Units.LITRE.divide(tech.units.indriya.unit.Units.MINUTE)));
|
||||
@@ -309,6 +310,11 @@ public final class Units extends CustomUnits {
|
||||
SimpleUnitFormat.getInstance().label(VOLT_AMPERE_HOUR, "VAh");
|
||||
SimpleUnitFormat.getInstance().label(WATT_HOUR, "Wh");
|
||||
SimpleUnitFormat.getInstance().label(WATT_SECOND, "Ws");
|
||||
|
||||
// workarounds for https://github.com/unitsofmeasurement/indriya/issues/409
|
||||
SimpleUnitFormat.getInstance().alias(MONTH, "mo");
|
||||
SimpleUnitFormat.getInstance().alias(WEEK, "wk");
|
||||
SimpleUnitFormat.getInstance().alias(YEAR, "y");
|
||||
}
|
||||
|
||||
private Units() {
|
||||
|
||||
@@ -416,6 +416,16 @@ public class UnitsTest {
|
||||
assertThat(converted.doubleValue(), is(closeTo(4184.0, DEFAULT_ERROR)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testYearMonthDay() {
|
||||
QuantityType<?> year = QuantityType.valueOf("1 y");
|
||||
assertThat(year.toString(), is("1 year"));
|
||||
QuantityType<?> converted = year.toUnit("d");
|
||||
assertThat(converted.doubleValue(), is(closeTo(365.2425, DEFAULT_ERROR)));
|
||||
QuantityType<?> converted2 = year.toUnit("mo");
|
||||
assertThat(converted2.doubleValue(), is(closeTo(12.0, DEFAULT_ERROR)));
|
||||
}
|
||||
|
||||
private static class QuantityEquals extends IsEqual<Quantity<?>> {
|
||||
private Quantity<?> quantity;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user