Search in sources :

Example 1 with Time

use of javax.measure.quantity.Time in project uom-se by unitsofmeasurement.

the class QuantitiesTest method toTest.

@Test
public void toTest() {
    Quantity<Time> minute = Quantities.getQuantity(BigDecimal.ONE, Units.YEAR);
    Quantity<Time> second = minute.to(Units.SECOND);
    BigDecimal value = (BigDecimal) second.getValue();
    value.setScale(4, RoundingMode.HALF_EVEN);
    BigDecimal expected = BigDecimal.valueOf(31556952);
    Assert.assertEquals(expected.setScale(4, RoundingMode.HALF_EVEN), value.setScale(4, RoundingMode.HALF_EVEN));
}
Also used : Time(javax.measure.quantity.Time) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 2 with Time

use of javax.measure.quantity.Time in project uom-se by unitsofmeasurement.

the class TimeQuantitiesTest method ofLocalTimeTemporalAdjustTest.

@Test
public void ofLocalTimeTemporalAdjustTest() {
    LocalTime a = LocalTime.MIDNIGHT;
    TemporalAdjuster temporalAdjuster = (temporal) -> temporal.plus(12L, ChronoUnit.HOURS);
    Quantity<Time> time = TimeQuantities.getQuantity(a, () -> temporalAdjuster);
    Assert.assertEquals(Integer.valueOf(12), Integer.valueOf(time.getValue().intValue()));
    Assert.assertEquals(Units.HOUR, time.getUnit());
}
Also used : Unit(javax.measure.Unit) Month(java.time.Month) HOUR(tec.uom.se.unit.Units.HOUR) Test(org.junit.Test) DAY(tec.uom.se.unit.Units.DAY) ChronoUnit(java.time.temporal.ChronoUnit) Year(java.time.Year) Quantity(javax.measure.Quantity) Quantities(tec.uom.se.quantity.Quantities) TimeQuantities(tec.uom.se.quantity.time.TimeQuantities) Units(tec.uom.se.unit.Units) DayOfWeek(java.time.DayOfWeek) LocalDate(java.time.LocalDate) LocalTime(java.time.LocalTime) TemporalAdjusters(java.time.temporal.TemporalAdjusters) MINUTE(tec.uom.se.unit.Units.MINUTE) SECOND(tec.uom.se.unit.Units.SECOND) TemporalAdjuster(java.time.temporal.TemporalAdjuster) Assert(org.junit.Assert) TemporalQuantity(tec.uom.se.quantity.time.TemporalQuantity) Time(javax.measure.quantity.Time) LocalTime(java.time.LocalTime) TemporalAdjuster(java.time.temporal.TemporalAdjuster) LocalTime(java.time.LocalTime) Time(javax.measure.quantity.Time) Test(org.junit.Test)

Example 3 with Time

use of javax.measure.quantity.Time in project uom-se by unitsofmeasurement.

the class TimeQuantitiesTest method ofTemporalTest.

@Test
public void ofTemporalTest() {
    LocalDate a = Year.of(2015).atMonth(Month.JANUARY).atDay(9);
    LocalDate b = Year.of(2015).atMonth(Month.JANUARY).atDay(10);
    Quantity<Time> time = TimeQuantities.getQuantity(a, b);
    Assert.assertEquals(Integer.valueOf(1), Integer.valueOf(time.getValue().intValue()));
    Assert.assertEquals(Units.DAY, time.getUnit());
}
Also used : LocalTime(java.time.LocalTime) Time(javax.measure.quantity.Time) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 4 with Time

use of javax.measure.quantity.Time in project indriya by unitsofmeasurement.

the class TimeQuantitiesTest method ofLocalTimeTemporalAdjustTest.

@Test
public void ofLocalTimeTemporalAdjustTest() {
    LocalTime a = LocalTime.MIDNIGHT;
    TemporalAdjuster temporalAdjuster = (temporal) -> temporal.plus(12L, ChronoUnit.HOURS);
    Quantity<Time> time = TimeQuantities.getQuantity(a, () -> temporalAdjuster);
    assertEquals(Integer.valueOf(12), Integer.valueOf(time.getValue().intValue()));
    assertEquals(Units.HOUR, time.getUnit());
}
Also used : Unit(javax.measure.Unit) HERTZ(tech.units.indriya.unit.Units.HERTZ) MINUTE(tech.units.indriya.unit.Units.MINUTE) Quantity(javax.measure.Quantity) DAY(tech.units.indriya.unit.Units.DAY) TimeQuantities(tech.units.indriya.quantity.time.TimeQuantities) LocalTime(java.time.LocalTime) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Frequency(javax.measure.quantity.Frequency) Month(java.time.Month) TemporalQuantity(tech.units.indriya.quantity.time.TemporalQuantity) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) ChronoUnit(java.time.temporal.ChronoUnit) SECOND(tech.units.indriya.unit.Units.SECOND) Year(java.time.Year) Quantities(tech.units.indriya.quantity.Quantities) DayOfWeek(java.time.DayOfWeek) LocalDate(java.time.LocalDate) TemporalAdjusters(java.time.temporal.TemporalAdjusters) HOUR(tech.units.indriya.unit.Units.HOUR) TimeUnitQuantity(tech.units.indriya.quantity.time.TimeUnitQuantity) TemporalAdjuster(java.time.temporal.TemporalAdjuster) Time(javax.measure.quantity.Time) Units(tech.units.indriya.unit.Units) LocalTime(java.time.LocalTime) TemporalAdjuster(java.time.temporal.TemporalAdjuster) LocalTime(java.time.LocalTime) Time(javax.measure.quantity.Time) Test(org.junit.jupiter.api.Test)

Example 5 with Time

use of javax.measure.quantity.Time in project indriya by unitsofmeasurement.

the class QuantitiesTest method toTest.

@Test
public void toTest() {
    Quantity<Time> minute = Quantities.getQuantity(BigDecimal.ONE, Units.YEAR);
    Quantity<Time> second = minute.to(Units.SECOND);
    BigDecimal value = (BigDecimal) second.getValue();
    value.setScale(4, RoundingMode.HALF_EVEN);
    BigDecimal expected = BigDecimal.valueOf(31556952);
    assertEquals(expected.setScale(4, RoundingMode.HALF_EVEN), value.setScale(4, RoundingMode.HALF_EVEN));
}
Also used : Time(javax.measure.quantity.Time) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Aggregations

Time (javax.measure.quantity.Time)15 LocalTime (java.time.LocalTime)10 Test (org.junit.Test)7 Test (org.junit.jupiter.api.Test)7 LocalDate (java.time.LocalDate)6 BigDecimal (java.math.BigDecimal)2 DayOfWeek (java.time.DayOfWeek)2 Month (java.time.Month)2 Year (java.time.Year)2 ChronoUnit (java.time.temporal.ChronoUnit)2 TemporalAdjuster (java.time.temporal.TemporalAdjuster)2 TemporalAdjusters (java.time.temporal.TemporalAdjusters)2 Quantity (javax.measure.Quantity)2 Unit (javax.measure.Unit)2 TemporalQuantity (tec.uom.se.quantity.time.TemporalQuantity)2 TemporalQuantity (tech.units.indriya.quantity.time.TemporalQuantity)2 TimeUnitQuantity (tech.units.indriya.quantity.time.TimeUnitQuantity)2 Instant (java.time.Instant)1 TimeUnit (java.util.concurrent.TimeUnit)1 Frequency (javax.measure.quantity.Frequency)1