Java Code Examples for java.time.LocalTime#isAfter()
The following examples show how to use
java.time.LocalTime#isAfter() .
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: RangeFilterTests.java From morpheus-core with Apache License 2.0 | 6 votes |
@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 2
Source File: UpdateService.java From sailfish-core with Apache License 2.0 | 5 votes |
private boolean isTimeForAutoUpdate(LocalDateTime dateTime) { if (!enableAutoUpdate) { return false; } LocalTime time = dateTime.toLocalTime(); return DayOfWeek.from(dateTime) == dayForUpdate && time.isAfter(fromTime) && time.isBefore(toTime); }
Example 3
Source File: EmailUtil.java From library with Apache License 2.0 | 5 votes |
/** * @return */ public static String getGreeting() { final LocalTime now = LocalTime.now(); if (now.isAfter(LocalTime.of(12, 0))) { return MessageSource.get("mail.good-evening"); } else if (now.isBefore(LocalTime.of(12, 0))) { return MessageSource.get("mail.good-morning"); } else { return MessageSource.get("mail.good-night"); } }
Example 4
Source File: TimeOfDayConditionHandler.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isSatisfied(Map<String, Object> inputs) { if (startTime == null || endTime == null) { logger.warn("Time condition with id {} is not well configured: startTime={} endTime = {}", module.getId(), startTime, endTime); return false; } LocalTime currentTime = LocalTime.now().truncatedTo(ChronoUnit.MINUTES); // If the current time equals the start time, the condition is always true. if (currentTime.equals(startTime)) { logger.debug("Time condition with id {} evaluated, that the current time {} equals the start time: {}", module.getId(), currentTime, startTime); return true; } // If the start time is before the end time, the condition will evaluate as true, // if the current time is between the start time and the end time. if (startTime.isBefore(endTime)) { if (currentTime.isAfter(startTime) && currentTime.isBefore(endTime)) { logger.debug("Time condition with id {} evaluated, that {} is between {} and {}.", module.getId(), currentTime, startTime, endTime); return true; } } // If the start time is set after the end time, the time values wrap around the midnight mark. // So if the start time is 19:00 and the end time is 07:00, the condition will be true from // 19:00 to 23:59 and 00:00 to 07:00. else if (currentTime.isAfter(LocalTime.MIDNIGHT) && currentTime.isBefore(endTime) || currentTime.isAfter(startTime) && currentTime.isBefore(LocalTime.MAX)) { logger.debug("Time condition with id {} evaluated, that {} is between {} and {}, or between {} and {}.", module.getId(), currentTime, LocalTime.MIDNIGHT, endTime, startTime, LocalTime.MAX.truncatedTo(ChronoUnit.MINUTES)); return true; } // If none of these conditions apply false is returned. return false; }
Example 5
Source File: WeeklyPlanningServiceImp.java From axelor-open-suite with GNU Affero General Public License v3.0 | 5 votes |
@Override public BigDecimal getWorkingDayValueInHours( WeeklyPlanning weeklyPlanning, LocalDate date, LocalTime from, LocalTime to) { double value = 0; DayPlanning dayPlanning = this.findDayPlanning(weeklyPlanning, date); if (dayPlanning == null) { return BigDecimal.valueOf(value); } // Compute morning leave duration LocalTime morningFrom = dayPlanning.getMorningFrom(); LocalTime morningTo = dayPlanning.getMorningTo(); if (morningFrom != null && morningTo != null) { LocalTime morningBegin = from != null && from.isAfter(morningFrom) ? from : morningFrom; LocalTime morningEnd = to != null && to.isBefore(morningTo) ? to : morningTo; if (to != null && to.isBefore(morningBegin)) { return BigDecimal.ZERO; } else if (from == null || from.isBefore(morningEnd)) { value += ChronoUnit.MINUTES.between(morningBegin, morningEnd); } } // Compute afternoon leave duration LocalTime afternoonFrom = dayPlanning.getAfternoonFrom(); LocalTime afternoonTo = dayPlanning.getAfternoonTo(); if (afternoonFrom != null && afternoonTo != null) { LocalTime afternoonBegin = from != null && from.isAfter(afternoonFrom) ? from : afternoonFrom; LocalTime afternoonEnd = to != null && to.isBefore(afternoonTo) ? to : afternoonTo; if (from != null && from.isAfter(afternoonEnd)) { return BigDecimal.ZERO; } else if (to == null || to.isAfter(afternoonBegin)) { value += ChronoUnit.MINUTES.between(afternoonBegin, afternoonEnd); } } return BigDecimal.valueOf(value).divide(BigDecimal.valueOf(60), BigDecimal.ROUND_HALF_UP); }
Example 6
Source File: TimeOfDayConditionHandler.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public boolean isSatisfied(Map<String, Object> inputs) { if (startTime == null || endTime == null) { logger.warn("Time condition with id {} is not well configured: startTime={} endTime = {}", module.getId(), startTime, endTime); return false; } LocalTime currentTime = LocalTime.now().truncatedTo(ChronoUnit.MINUTES); // If the current time equals the start time, the condition is always true. if (currentTime.equals(startTime)) { logger.debug("Time condition with id {} evaluated, that the current time {} equals the start time: {}", module.getId(), currentTime, startTime); return true; } // If the start time is before the end time, the condition will evaluate as true, // if the current time is between the start time and the end time. if (startTime.isBefore(endTime)) { if (currentTime.isAfter(startTime) && currentTime.isBefore(endTime)) { logger.debug("Time condition with id {} evaluated, that {} is between {} and {}.", module.getId(), currentTime, startTime, endTime); return true; } } // If the start time is set after the end time, the time values wrap around the midnight mark. // So if the start time is 19:00 and the end time is 07:00, the condition will be true from // 19:00 to 23:59 and 00:00 to 07:00. else if (currentTime.isAfter(LocalTime.MIDNIGHT) && currentTime.isBefore(endTime) || currentTime.isAfter(startTime) && currentTime.isBefore(LocalTime.MAX)) { logger.debug("Time condition with id {} evaluated, that {} is between {} and {}, or between {} and {}.", module.getId(), currentTime, LocalTime.MIDNIGHT, endTime, startTime, LocalTime.MAX.truncatedTo(ChronoUnit.MINUTES)); return true; } // If none of these conditions apply false is returned. return false; }
Example 7
Source File: WorkTimeRule.java From eas-ddd with Apache License 2.0 | 4 votes |
public boolean isLate(LocalTime punchedTime) { return punchedTime.isAfter(startWork.plusMinutes(allowableLateMinutes)); }
Example 8
Source File: PDTHelper.java From ph-commons with Apache License 2.0 | 4 votes |
@Nonnull public static LocalTime getMax (@Nonnull final LocalTime aTime1, @Nonnull final LocalTime aTime2) { return aTime1.isAfter (aTime2) ? aTime1 : aTime2; }
Example 9
Source File: DateUtils.java From Raincat with GNU Lesser General Public License v3.0 | 3 votes |
/** * 判断时间是否在指定的时间段之类. * * @param date 需要判断的时间 * @param start 时间段的起始时间 * @param end 时间段的截止时间 * @return true or false */ public static boolean isBetween(final LocalTime date, final LocalTime start, final LocalTime end) { if (date == null || start == null || end == null) { throw new IllegalArgumentException("日期不能为空"); } return date.isAfter(start) && date.isBefore(end); }
Example 10
Source File: DateUtil.java From FEBS-Cloud with Apache License 2.0 | 2 votes |
/** * 判断当前时间是否在指定时间范围 * * @param from 开始时间 * @param to 结束时间 * @return 结果 */ public static boolean between(LocalTime from, LocalTime to) { LocalTime now = LocalTime.now(); return now.isAfter(from) && now.isBefore(to); }
Example 11
Source File: TimeSection.java From OEE-Designer with MIT License | 2 votes |
/** * Returns true if the given time is within the range between * section.getStart() and section.getStop() * @param VALUE * @return true if the given time is within the range of the section */ public boolean contains(final LocalTime VALUE) { return VALUE.isAfter(getStart()) && VALUE.isBefore(getStop()); }
Example 12
Source File: RangeOfLocalTimes.java From morpheus-core with Apache License 2.0 | 2 votes |
/** * Checks that the value specified is in the bounds of this range * @param value the value to check if in bounds * @return true if in bounds */ private boolean inBounds(LocalTime value) { return ascend ? value.compareTo(start()) >=0 && value.isBefore(end()) : value.compareTo(start()) <=0 && value.isAfter(end()); }
Example 13
Source File: TimeSection.java From tilesfx with Apache License 2.0 | 2 votes |
/** * Returns true if the given time is within the range between * section.getStart() and section.getStop() * @param VALUE * @return true if the given time is within the range of the section */ public boolean contains(final LocalTime VALUE) { return VALUE.isAfter(getStart()) && VALUE.isBefore(getStop()); }
Example 14
Source File: TimeSection.java From Medusa with Apache License 2.0 | 2 votes |
/** * Returns true if the given time is within the range between * section.getStart() and section.getStop() * @param VALUE * @return true if the given time is within the range of the section */ public boolean contains(final LocalTime VALUE) { return VALUE.isAfter(getStart()) && VALUE.isBefore(getStop()); }