/** * 判断某个团购活动是否已经过期 * * @return */ public boolean isExpired(LitemallGrouponRules rules) { return (rules == null || rules.getExpireTime().isBefore(LocalDateTime.now())); }
/** * 判断时间是否在指定的时间段之类. * * @param date 需要判断的时间 * @param start 时间段的起始时间 * @param end 时间段的截止时间 * @return true or false */ public static boolean isBetween(final LocalDateTime date, final LocalDateTime start, final LocalDateTime end) { if (date == null || start == null || end == null) { throw new IllegalArgumentException("日期不能为空"); } return date.isAfter(start) && date.isBefore(end); }
public static Integer getUserId(String token) { UserToken userToken = tokenMap.get(token); if (userToken == null) { return null; } if (userToken.getExpireTime().isBefore(LocalDateTime.now())) { tokenMap.remove(token); idMap.remove(userToken.getUserId()); return null; } return userToken.getUserId(); }
public static String getSessionKey(Integer userId) { UserToken userToken = idMap.get(userId); if (userToken == null) { return null; } if (userToken.getExpireTime().isBefore(LocalDateTime.now())) { tokenMap.remove(userToken.getToken()); idMap.remove(userId); return null; } return userToken.getSessionKey(); }
/** * 获取缓存的验证码 * * @param phoneNumber 关联的电话号码 * @return 验证码 */ public static String getCachedCaptcha(String phoneNumber) { //没有这个电话记录 if (captchaCodeCache.get(phoneNumber) == null) return null; //有电话记录但是已经过期 if (captchaCodeCache.get(phoneNumber).getExpireTime().isBefore(LocalDateTime.now())) { return null; } return captchaCodeCache.get(phoneNumber).getCode(); } }
public static boolean validate(final Object value, final LocalDateTime then) { if (value == null) { return true; } LocalDateTimeConverter ldtc = (LocalDateTimeConverter) TypeConverterManager.get().lookup(LocalDateTime.class); LocalDateTime now = ldtc.convert(value); return now.isBefore(then); } }
/** * Gets the time gap between now and next backup time. * * @return the time gap to next backup */ private long getTimeToNextBackup() { LocalDateTime now = LocalDateTime.now(Clock.systemUTC()); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("H:mm"); LocalTime backupTime = LocalTime.parse(ServerConfiguration .get(PropertyKey.MASTER_DAILY_BACKUP_TIME), formatter); LocalDateTime nextBackupTime = now.withHour(backupTime.getHour()) .withMinute(backupTime.getMinute()); if (nextBackupTime.isBefore(now)) { nextBackupTime = nextBackupTime.plusDays(1); } return ChronoUnit.MILLIS.between(now, nextBackupTime); }
protected LineFilterResult acceptsLogEntry(Level logLevel, LocalDateTime logTimestamp) { if (logTimestamp == null || logLevel == null) { throw new IllegalArgumentException(); } LineFilterResult result; if (endDate != null && logTimestamp.isAfter(endDate)) { result = LineFilterResult.REMAINDER_OF_FILE_REJECTED; } else if (startDate != null && logTimestamp.isBefore(startDate)) { result = LineFilterResult.LINE_REJECTED; } else { if (thisLevelOnly) { result = logLevel.intLevel() == thisLogLevel.intLevel() ? LineFilterResult.LINE_ACCEPTED : LineFilterResult.LINE_REJECTED; } else { result = logLevel.isMoreSpecificThan(thisLogLevel) ? LineFilterResult.LINE_ACCEPTED : LineFilterResult.LINE_REJECTED; } } resultOfPreviousLine = result; return result; }
/** * Verifies that the actual {@code LocalDateTime} is <b>strictly</b> before the given one. * <p> * Example : * <pre><code class='java'> assertThat(parse("2000-01-01T23:59:59")).isBefore(parse("2000-01-02T00:00:00"));</code></pre> * * @param other the given {@link LocalDateTime}. * @return this assertion object. * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}. * @throws IllegalArgumentException if other {@code LocalDateTime} is {@code null}. * @throws AssertionError if the actual {@code LocalDateTime} is not strictly before the given one. */ public SELF isBefore(LocalDateTime other) { Objects.instance().assertNotNull(info, actual); assertLocalDateTimeParameterIsNotNull(other); if (!actual.isBefore(other)) { throw Failures.instance().failure(info, shouldBeBefore(actual, other)); } return myself; }
/** * Verifies that the actual {@code LocalDateTime} is after or equals to the given one. * <p> * Example : * <pre><code class='java'> assertThat(parse("2000-01-01T00:00:00")).isAfterOrEqualTo(parse("2000-01-01T00:00:00")) * .isAfterOrEqualTo(parse("1999-12-31T23:59:59"));</code></pre> * * @param other the given {@link LocalDateTime}. * @return this assertion object. * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}. * @throws IllegalArgumentException if other {@code LocalDateTime} is {@code null}. * @throws AssertionError if the actual {@code LocalDateTime} is not after or equals to the given one. */ public SELF isAfterOrEqualTo(LocalDateTime other) { Objects.instance().assertNotNull(info, actual); assertLocalDateTimeParameterIsNotNull(other); if (actual.isBefore(other)) { throw Failures.instance().failure(info, shouldBeAfterOrEqualsTo(actual, other)); } return myself; }
/** * Verifies that the actual {@code LocalDateTime} is <b>strictly</b> before the given one. * <p> * Example : * <pre><code class='java'> assertThat(parse("2000-01-01T23:59:59")).isBefore(parse("2000-01-02T00:00:00"));</code></pre> * * @param other the given {@link LocalDateTime}. * @return this assertion object. * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}. * @throws IllegalArgumentException if other {@code LocalDateTime} is {@code null}. * @throws AssertionError if the actual {@code LocalDateTime} is not strictly before the given one. */ public SELF isBefore(LocalDateTime other) { Objects.instance().assertNotNull(info, actual); assertLocalDateTimeParameterIsNotNull(other); if (!actual.isBefore(other)) { throw Failures.instance().failure(info, shouldBeBefore(actual, other)); } return myself; }
/** * Verifies that the actual {@code LocalDateTime} is after or equals to the given one. * <p> * Example : * <pre><code class='java'> assertThat(parse("2000-01-01T00:00:00")).isAfterOrEqualTo(parse("2000-01-01T00:00:00")) * .isAfterOrEqualTo(parse("1999-12-31T23:59:59"));</code></pre> * * @param other the given {@link LocalDateTime}. * @return this assertion object. * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}. * @throws IllegalArgumentException if other {@code LocalDateTime} is {@code null}. * @throws AssertionError if the actual {@code LocalDateTime} is not after or equals to the given one. */ public SELF isAfterOrEqualTo(LocalDateTime other) { Objects.instance().assertNotNull(info, actual); assertLocalDateTimeParameterIsNotNull(other); if (actual.isBefore(other)) { throw Failures.instance().failure(info, shouldBeAfterOrEqualsTo(actual, other)); } return myself; }
LocalDateTime now = LocalDateTime.now(); if (timeType.equals(CouponConstant.TIME_TYPE_TIME)) { if (now.isBefore(coupon.getStartTime()) || now.isAfter(coupon.getEndTime())) { return null;
while (LocalDateTime.now().isBefore(testEnd)) { events.put(generateClickEvent());
/** * Calculate if the token is expired against the given time. * It also returns true even if the token is not initialized (i.e. object newly created). * * @param givenTime To calculate if the token is expired against the givenTime. * @param tokenExpiresInBuffer A positive integer in seconds to act as additional buffer to the calculation. * This causes the OAuthToken to expire earlier then the stated expiry-time given * by the authorization server. * * @return true if object is not-initialized, or expired, or expired early due to buffer */ public boolean isExpired(@NonNull LocalDateTime givenTime, int tokenExpiresInBuffer) { return createdOn == null || createdOn.plusSeconds(expiresIn).minusSeconds(tokenExpiresInBuffer).isBefore(givenTime); }
if (date.isAfter(now.plus(Duration.ofMinutes(RestConstants.REQUEST_DURATION_MINUTES))) || date.isBefore(now.minus(Duration.ofMinutes(RestConstants.REQUEST_DURATION_MINUTES)))) { throw new RestException(HttpStatus.FORBIDDEN.value(), String.format("requestTimeTooSkewed"));
/** * Validates that this window is after the previous one. * * @param previous the previous window, not null * @throws IllegalStateException if the window order is invalid */ void validateWindowOrder(TZWindow previous) { if (windowEnd.isBefore(previous.windowEnd)) { throw new IllegalStateException("Windows must be added in date-time order: " + windowEnd + " < " + previous.windowEnd); } }
public PublishedEvent waitForEvent(BlockingQueue<PublishedEvent> publishedEvents, Int128 eventId, LocalDateTime deadline, String eventData) throws InterruptedException { while (LocalDateTime.now().isBefore(deadline)) { long millis = ChronoUnit.MILLIS.between(deadline, LocalDateTime.now()); PublishedEvent event = publishedEvents.poll(millis, TimeUnit.MILLISECONDS); if (event != null && event.getId().equals(eventId.asString()) && eventData.equals(event.getEventData())) return event; } throw new RuntimeException("event not found: " + eventId); }
public boolean isDateInRange(LocalDateTime date) { if (from().isPresent() && from().get().isAfter(date)){ return false; } if (to().isPresent() && to().get().isBefore(date)){ return false; } return true; } }
@Override public final boolean isValid(final LocalDateTime pvalue, final ConstraintValidatorContext pcontext) { if (pvalue == null) { return true; } final LocalDateTime dateLimit = LocalDateTime.now().minusYears(minYears).withHour(0) .withMinute(0).withSecond(0).withNano(0); return !dateLimit.isBefore(pvalue.withHour(0).withMinute(0).withSecond(0).withNano(0)); } }