java.time.LocalTime#isBefore ( )源码实例Demo

下面列出了java.time.LocalTime#isBefore ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: morpheus-core   文件: RangeBasicTests.java
@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);
    }
}
 
源代码2 项目: morpheus-core   文件: RangeFilterTests.java
@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++;
    }
}
 
源代码3 项目: logging-log4j2   文件: TimeFilter.java
TimeFilter(final LocalTime start, final LocalTime end, final ZoneId timeZone, final Result onMatch,
        final Result onMismatch, LocalDate now) {
    super(onMatch, onMismatch);
    this.startTime = start;
    this.endTime = end;
    this.timeZone = timeZone;
    this.start = ZonedDateTime.of(now, startTime, timeZone).withEarlierOffsetAtOverlap().toInstant().toEpochMilli();
    long endMillis = ZonedDateTime.of(now, endTime, timeZone).withEarlierOffsetAtOverlap().toInstant().toEpochMilli();
    if (end.isBefore(start)) {
        // End time must be tomorrow.
        endMillis += DAY_MS;
    }
    duration = startTime.isBefore(endTime) ? Duration.between(startTime, endTime).toMillis() :
        Duration.between(startTime, endTime).plusHours(24).toMillis();
    long difference = (endMillis - this.start) - duration;
    if (difference != 0) {
        // Handle switch from standard time to daylight time and daylight time to standard time.
        endMillis -= difference;
    }
    this.end = endMillis;
}
 
源代码4 项目: sailfish-core   文件: UpdaterConfigBean.java
private void validateSettings(UpdateServiceSettings settings) {
    if (settings.isEnableAutoUpdate()) {
        LocalTime fromTime = DateTimeUtility.toLocalTime(from);
        LocalTime toTime = DateTimeUtility.toLocalTime(to);
        if (!fromTime.isBefore(toTime)) {
            throw new IllegalArgumentException("'From' must be before 'To'");
        }
    }
}
 
源代码5 项目: sailfish-core   文件: UpdateService.java
private boolean isTimeForAutoUpdate(LocalDateTime dateTime) {
    if (!enableAutoUpdate) {
        return false;
    }
    LocalTime time = dateTime.toLocalTime();
    return DayOfWeek.from(dateTime) == dayForUpdate && time.isAfter(fromTime) && time.isBefore(toTime);
}
 
源代码6 项目: library   文件: EmailUtil.java
/**
 * @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");
    }
}
 
源代码7 项目: openhab-core   文件: TimeOfDayConditionHandler.java
@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;
}
 
@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);
}
 
源代码9 项目: smarthome   文件: TimeOfDayConditionHandler.java
@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;
}
 
源代码10 项目: eas-ddd   文件: WorkTimeRule.java
public boolean isLeaveEarly(LocalTime punchedTime) {
    return punchedTime.isBefore(endWork.minusMinutes(allowableLeaveEarlyMinutes));
}
 
源代码11 项目: JavaWeb   文件: DateUtil.java
public static boolean isDateEarly(LocalTime localTime1,LocalTime localTime2){
	return localTime1.isBefore(localTime2);
}
 
源代码12 项目: ph-commons   文件: PDTHelper.java
@Nonnull
public static LocalTime getMin (@Nonnull final LocalTime aTime1, @Nonnull final LocalTime aTime2)
{
  return aTime1.isBefore (aTime2) ? aTime1 : aTime2;
}
 
源代码13 项目: Raincat   文件: DateUtils.java
/**
 * 判断时间是否在指定的时间段之类.
 *
 * @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);
}
 
源代码14 项目: FEBS-Cloud   文件: DateUtil.java
/**
 * 判断当前时间是否在指定时间范围
 *
 * @param from 开始时间
 * @param to   结束时间
 * @return 结果
 */
public static boolean between(LocalTime from, LocalTime to) {
    LocalTime now = LocalTime.now();
    return now.isAfter(from) && now.isBefore(to);
}
 
源代码15 项目: OEE-Designer   文件: TimeSection.java
/**
 * 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());
}
 
源代码16 项目: morpheus-core   文件: RangeOfLocalTimes.java
/**
 * 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());
}
 
源代码17 项目: tilesfx   文件: TimeSection.java
/**
 * 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());
}
 
源代码18 项目: Medusa   文件: TimeSection.java
/**
 * 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());
}