Java Code Examples for java.time.LocalTime#minus()

The following examples show how to use java.time.LocalTime#minus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RangeBasicTests.java    From morpheus-core with Apache License 2.0 6 votes vote down vote up
@Test(dataProvider = "localTimeRanges")
public void testRangeOfLocalTimes(LocalTime start, LocalTime end, Duration step, boolean parallel) {
    final Range<LocalTime> range = Range.of(start, end, step);
    final Array<LocalTime> array = range.toArray(parallel);
    final boolean ascend = start.isBefore(end);
    final int expectedLength = (int)Math.ceil(Math.abs((double)ChronoUnit.SECONDS.between(start, end)) / (double)step.getSeconds());
    Assert.assertEquals(array.length(), expectedLength);
    Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_TIME);
    Assert.assertTrue(!array.style().isSparse());
    Assert.assertEquals(range.start(), start, "The range start");
    Assert.assertEquals(range.end(), end, "The range end");
    LocalTime expected = null;
    for (int i=0; i<array.length(); ++i) {
        final LocalTime actual = array.getValue(i);
        expected = expected == null ? start : ascend ? expected.plus(step) : expected.minus(step);
        Assert.assertEquals(actual, expected, "Value matches at " + i);
        Assert.assertTrue(ascend ? actual.compareTo(start) >=0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + i);
    }
}
 
Example 2
Source File: RangeFilterTests.java    From morpheus-core with Apache License 2.0 6 votes vote down vote up
@Test(dataProvider = "LocalTimeRanges")
public void testRangeOfLocalTimes(LocalTime start, LocalTime end, Duration step, boolean parallel) {
    final boolean ascend = start.isBefore(end);
    final Range<LocalTime> range = Range.of(start, end, step, v -> v.getHour() == 6);
    final Array<LocalTime> array = range.toArray(parallel);
    final LocalTime first = array.first(v -> true).map(ArrayValue::getValue).get();
    final LocalTime last = array.last(v -> true).map(ArrayValue::getValue).get();
    Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_TIME);
    Assert.assertTrue(!array.style().isSparse());
    Assert.assertEquals(range.start(), start, "The range start");
    Assert.assertEquals(range.end(), end, "The range end");
    int index = 0;
    LocalTime value = first;
    while (ascend ? value.isBefore(last) : value.isAfter(last)) {
        final LocalTime actual = array.getValue(index);
        Assert.assertEquals(actual, value, "Value matches at " + index);
        Assert.assertTrue(ascend ? actual.compareTo(start) >= 0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + index);
        value = ascend ? value.plus(step) : value.minus(step);
        while (value.getHour() == 6) value = ascend ? value.plus(step) : value.minus(step);
        index++;
    }
}
 
Example 3
Source File: TimeOfDayConditionHandlerTest.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * This checks if the condition on its own works properly.
 */
@Test
public void assertThatConditionWorks() {
    LocalTime currentTime = LocalTime.now().truncatedTo(ChronoUnit.MINUTES);
    LocalTime beforeCurrentTime = currentTime.minus(Duration.ofMinutes(2));
    LocalTime afterCurrentTime = currentTime.plus(Duration.ofMinutes(2));

    // Time is between start and end time -> should return true.
    TimeOfDayConditionHandler handler = getTimeOfDayConditionHandler(beforeCurrentTime.toString(),
            afterCurrentTime.toString());
    assertThat(handler.isSatisfied(Collections.emptyMap()), is(true));

    // Time is equal to start time -> should return true
    handler = getTimeOfDayConditionHandler(currentTime.toString(), afterCurrentTime.toString());
    assertThat(handler.isSatisfied(Collections.emptyMap()), is(true));

    // Time is equal to end time -> should return false
    handler = getTimeOfDayConditionHandler(beforeCurrentTime.toString(), currentTime.toString());
    assertThat(handler.isSatisfied(Collections.emptyMap()), is(false));

    // Start value is in the future & end value is in the past
    // -> should return false
    handler = getTimeOfDayConditionHandler(afterCurrentTime.toString(), beforeCurrentTime.toString());
    assertThat(handler.isSatisfied(Collections.emptyMap()), is(false));

    // Start & end time are in the future & start time is after the end time
    // -> should return true
    handler = getTimeOfDayConditionHandler(afterCurrentTime.plus(Duration.ofMinutes(2)).toString(),
            afterCurrentTime.toString());
    assertThat(handler.isSatisfied(Collections.emptyMap()), is(true));
}
 
Example 4
Source File: TimeOfDayConditionHandlerTest.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Condition getPassingCondition() {
    LocalTime currentTime = LocalTime.now().truncatedTo(ChronoUnit.MINUTES);
    LocalTime beforeCurrentTime = currentTime.minus(Duration.ofMinutes(2));
    LocalTime afterCurrentTime = currentTime.plus(Duration.ofMinutes(2));
    return getTimeCondition(beforeCurrentTime.toString(), afterCurrentTime.toString());
}
 
Example 5
Source File: TimeOfDayConditionHandlerTest.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Configuration getFailingConfiguration() {
    LocalTime currentTime = LocalTime.now().truncatedTo(ChronoUnit.MINUTES);
    LocalTime beforeCurrentTime = currentTime.minus(Duration.ofMinutes(2));
    LocalTime afterCurrentTime = currentTime.plus(Duration.ofMinutes(2));
    return getTimeConfiguration(afterCurrentTime.toString(), beforeCurrentTime.toString());
}
 
Example 6
Source File: TimeOfDayConditionHandlerTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * This checks if the condition on its own works properly.
 */
@Test
public void assertThatConditionWorks() {
    LocalTime currentTime = LocalTime.now().truncatedTo(ChronoUnit.MINUTES);
    LocalTime beforeCurrentTime = currentTime.minus(Duration.ofMinutes(2));
    LocalTime afterCurrentTime = currentTime.plus(Duration.ofMinutes(2));

    // Time is between start and end time -> should return true.
    TimeOfDayConditionHandler handler = getTimeOfDayConditionHandler(beforeCurrentTime.toString(),
            afterCurrentTime.toString());
    assertThat(handler.isSatisfied(null), is(true));

    // Time is equal to start time -> should return true
    handler = getTimeOfDayConditionHandler(currentTime.toString(), afterCurrentTime.toString());
    assertThat(handler.isSatisfied(null), is(true));

    // Time is equal to end time -> should return false
    handler = getTimeOfDayConditionHandler(beforeCurrentTime.toString(), currentTime.toString());
    assertThat(handler.isSatisfied(null), is(false));

    // Start value is in the future & end value is in the past
    // -> should return false
    handler = getTimeOfDayConditionHandler(afterCurrentTime.toString(), beforeCurrentTime.toString());
    assertThat(handler.isSatisfied(null), is(false));

    // Start & end time are in the future & start time is after the end time
    // -> should return true
    handler = getTimeOfDayConditionHandler(afterCurrentTime.plus(Duration.ofMinutes(2)).toString(),
            afterCurrentTime.toString());
    assertThat(handler.isSatisfied(null), is(true));
}
 
Example 7
Source File: TimeOfDayConditionHandlerTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Condition getPassingCondition() {
    LocalTime currentTime = LocalTime.now().truncatedTo(ChronoUnit.MINUTES);
    LocalTime beforeCurrentTime = currentTime.minus(Duration.ofMinutes(2));
    LocalTime afterCurrentTime = currentTime.plus(Duration.ofMinutes(2));
    return getTimeCondition(beforeCurrentTime.toString(), afterCurrentTime.toString());
}
 
Example 8
Source File: TimeOfDayConditionHandlerTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Configuration getFailingConfiguration() {
    LocalTime currentTime = LocalTime.now().truncatedTo(ChronoUnit.MINUTES);
    LocalTime beforeCurrentTime = currentTime.minus(Duration.ofMinutes(2));
    LocalTime afterCurrentTime = currentTime.plus(Duration.ofMinutes(2));
    return getTimeConfiguration(afterCurrentTime.toString(), beforeCurrentTime.toString());
}