Java Code Examples for java.time.LocalDateTime#isBefore()
The following examples show how to use
java.time.LocalDateTime#isBefore() .
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: TimerChecker.java From FX-AlgorithmTrading with MIT License | 6 votes |
/** * すべてのスケールの基準時刻を指定時間まで進めます * @param nextBaseTime */ private void putForwardTimeToNext(LocalDateTime nextBaseTime) { for (Period period : TIMER_PERIODS) { LocalDateTime lastDateTime = lastDateTimeMap.get(period); LocalDateTime nextDateTime = nextDateTimeMap.get(period); // 指定時刻まで進める while (nextDateTime.isBefore(nextBaseTime)) { lastDateTime = nextDateTime; nextDateTime = nextDateTime.plus(period.getTimeInverval(), period.getChronoUnit()); } // LocalDateTime は immutable なので入れなおす lastDateTimeMap.put(period, lastDateTime); nextDateTimeMap.put(period, nextDateTime); } }
Example 2
Source File: ZoneRules.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Finds the offset info for a local date-time and transition. * * @param dt the date-time, not null * @param trans the transition, not null * @return the offset info, not null */ private Object findOffsetInfo(LocalDateTime dt, ZoneOffsetTransition trans) { LocalDateTime localTransition = trans.getDateTimeBefore(); if (trans.isGap()) { if (dt.isBefore(localTransition)) { return trans.getOffsetBefore(); } if (dt.isBefore(trans.getDateTimeAfter())) { return trans; } else { return trans.getOffsetAfter(); } } else { if (dt.isBefore(localTransition) == false) { return trans.getOffsetAfter(); } if (dt.isBefore(trans.getDateTimeAfter())) { return trans.getOffsetBefore(); } else { return trans; } } }
Example 3
Source File: ZoneRules.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Finds the offset info for a local date-time and transition. * * @param dt the date-time, not null * @param trans the transition, not null * @return the offset info, not null */ private Object findOffsetInfo(LocalDateTime dt, ZoneOffsetTransition trans) { LocalDateTime localTransition = trans.getDateTimeBefore(); if (trans.isGap()) { if (dt.isBefore(localTransition)) { return trans.getOffsetBefore(); } if (dt.isBefore(trans.getDateTimeAfter())) { return trans; } else { return trans.getOffsetAfter(); } } else { if (dt.isBefore(localTransition) == false) { return trans.getOffsetAfter(); } if (dt.isBefore(trans.getDateTimeAfter())) { return trans.getOffsetBefore(); } else { return trans; } } }
Example 4
Source File: ZoneRules.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * Finds the offset info for a local date-time and transition. * * @param dt the date-time, not null * @param trans the transition, not null * @return the offset info, not null */ private Object findOffsetInfo(LocalDateTime dt, ZoneOffsetTransition trans) { LocalDateTime localTransition = trans.getDateTimeBefore(); if (trans.isGap()) { if (dt.isBefore(localTransition)) { return trans.getOffsetBefore(); } if (dt.isBefore(trans.getDateTimeAfter())) { return trans; } else { return trans.getOffsetAfter(); } } else { if (dt.isBefore(localTransition) == false) { return trans.getOffsetAfter(); } if (dt.isBefore(trans.getDateTimeAfter())) { return trans.getOffsetBefore(); } else { return trans; } } }
Example 5
Source File: ZoneRules.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Finds the offset info for a local date-time and transition. * * @param dt the date-time, not null * @param trans the transition, not null * @return the offset info, not null */ private Object findOffsetInfo(LocalDateTime dt, ZoneOffsetTransition trans) { LocalDateTime localTransition = trans.getDateTimeBefore(); if (trans.isGap()) { if (dt.isBefore(localTransition)) { return trans.getOffsetBefore(); } if (dt.isBefore(trans.getDateTimeAfter())) { return trans; } else { return trans.getOffsetAfter(); } } else { if (dt.isBefore(localTransition) == false) { return trans.getOffsetAfter(); } if (dt.isBefore(trans.getDateTimeAfter())) { return trans.getOffsetBefore(); } else { return trans; } } }
Example 6
Source File: DomainApiUtils.java From yes-cart with Apache License 2.0 | 6 votes |
/** * Check availability of an object. * * @param enabled flag for on/off switch * @param availableFrom availability start (or null) * @param availableTo availability finish (or null) * @param now time now * * @return true if object is available given provided settings */ public static boolean isObjectAvailableNow(final boolean enabled, final LocalDateTime availableFrom, final LocalDateTime availableTo, final LocalDateTime now) { if (!enabled) { return false; } if (availableFrom != null && now.isBefore(availableFrom)) { return false; } if (availableTo != null && now.isAfter(availableTo)) { return false; } return true; }
Example 7
Source File: FieldHasDateBeforeValueAsserter.java From zerocode with Apache License 2.0 | 6 votes |
@Override public FieldAssertionMatcher actualEqualsToExpected(Object result) { boolean areEqual; if (result == null && expected == null) { areEqual = true; } else if (result == null) { areEqual = false; } else { LocalDateTime resultDT = null; try { resultDT = LocalDateTime.parse((String) result, DateTimeFormatter.ISO_DATE_TIME); areEqual = resultDT.isBefore(expected); } catch (DateTimeParseException ex) { areEqual = false; } } return areEqual ? aMatchingMessage() : aNotMatchingMessage(path, "Date Before:" + expected, result); }
Example 8
Source File: ZoneRules.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Finds the offset info for a local date-time and transition. * * @param dt the date-time, not null * @param trans the transition, not null * @return the offset info, not null */ private Object findOffsetInfo(LocalDateTime dt, ZoneOffsetTransition trans) { LocalDateTime localTransition = trans.getDateTimeBefore(); if (trans.isGap()) { if (dt.isBefore(localTransition)) { return trans.getOffsetBefore(); } if (dt.isBefore(trans.getDateTimeAfter())) { return trans; } else { return trans.getOffsetAfter(); } } else { if (dt.isBefore(localTransition) == false) { return trans.getOffsetAfter(); } if (dt.isBefore(trans.getDateTimeAfter())) { return trans.getOffsetBefore(); } else { return trans; } } }
Example 9
Source File: ZoneRules.java From JDKSourceCode1.8 with MIT License | 6 votes |
/** * Finds the offset info for a local date-time and transition. * * @param dt the date-time, not null * @param trans the transition, not null * @return the offset info, not null */ private Object findOffsetInfo(LocalDateTime dt, ZoneOffsetTransition trans) { LocalDateTime localTransition = trans.getDateTimeBefore(); if (trans.isGap()) { if (dt.isBefore(localTransition)) { return trans.getOffsetBefore(); } if (dt.isBefore(trans.getDateTimeAfter())) { return trans; } else { return trans.getOffsetAfter(); } } else { if (dt.isBefore(localTransition) == false) { return trans.getOffsetAfter(); } if (dt.isBefore(trans.getDateTimeAfter())) { return trans.getOffsetBefore(); } else { return trans; } } }
Example 10
Source File: ZoneRules.java From j2objc with Apache License 2.0 | 6 votes |
/** * Finds the offset info for a local date-time and transition. * * @param dt the date-time, not null * @param trans the transition, not null * @return the offset info, not null */ private Object findOffsetInfo(LocalDateTime dt, ZoneOffsetTransition trans) { LocalDateTime localTransition = trans.getDateTimeBefore(); if (trans.isGap()) { if (dt.isBefore(localTransition)) { return trans.getOffsetBefore(); } if (dt.isBefore(trans.getDateTimeAfter())) { return trans; } else { return trans.getOffsetAfter(); } } else { if (dt.isBefore(localTransition) == false) { return trans.getOffsetAfter(); } if (dt.isBefore(trans.getDateTimeAfter())) { return trans.getOffsetBefore(); } else { return trans; } } }
Example 11
Source File: Errors.java From cucumber-performance with MIT License | 5 votes |
public void update(LocalDateTime date) { if (date.isBefore(first)) first = date; if (date.isAfter(last)) last = date; incrementCount(); }
Example 12
Source File: WindowFunction.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Object apply(LocalDateTime value) { LocalDateTime ndt = LocalDateTime.now(); ChronoUnit cu = JDateUtil.getChronoUnit(this.period); switch (cu) { case SECONDS: ndt = LocalDateTime.of(value.getYear(), value.getMonthValue(), value.getDayOfMonth(), value.getHour(), value.getMinute(), 0); break; case MINUTES: ndt = LocalDateTime.of(value.getYear(), value.getMonthValue(), value.getDayOfMonth(), value.getHour(), 0, 0); break; case HOURS: ndt = LocalDateTime.of(value.getYear(), value.getMonthValue(), value.getDayOfMonth(), 0, 0, 0); break; case DAYS: ndt = LocalDateTime.of(value.getYear(), value.getMonthValue(), 1, 0, 0, 0); break; case MONTHS: ndt = LocalDateTime.of(value.getYear(), 1, 1, 0, 0, 0); break; case YEARS: int n = ((Period)period).getYears(); ndt = LocalDateTime.of(value.getYear() - n, 1, 1, 0, 0, 0); } while (ndt.isBefore(value)){ ndt = ndt.plus(period); } if (ndt.isAfter(value)) ndt = ndt.minus(period); return ndt; }
Example 13
Source File: MeteoDataInfo.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Interpolate data to a station point * * @param varName Variable name * @param x X coordinate of the station * @param y Y coordinate of the station * @param t Time coordinate of the station * @return Interpolated value */ public double toStation(String varName, double x, double y, LocalDateTime t) { List<LocalDateTime> times = this.getDataInfo().getTimes(); int tnum = times.size(); if (t.isBefore(times.get(0)) || t.isAfter(times.get(tnum - 1))) { return this.getDataInfo().getMissingValue(); } double ivalue = this.getDataInfo().getMissingValue(); double v_t1, v_t2; for (int i = 0; i < tnum; i++) { if (t.equals(times.get(i))) { ivalue = this.toStation(varName, x, y, i); break; } if (t.isBefore(times.get(i))) { v_t1 = this.toStation(varName, x, y, i - 1); v_t2 = this.toStation(varName, x, y, i); int h = (int)Duration.between(times.get(i - 1), t).toHours(); int th = (int)Duration.between(times.get(i - 1), times.get(i)).toHours(); ivalue = (v_t2 - v_t1) * h / th + v_t1; break; } } return ivalue; }
Example 14
Source File: ExchangeableTradingTimes.java From java-trader with Apache License 2.0 | 5 votes |
/** * 市场时间段 */ public MarketTimeStage getTimeStage(LocalDateTime time) { for(int i=0;i<marketTimes.length;i+=2 ) { LocalDateTime frameBegin = marketTimes[i]; LocalDateTime frameEnd = marketTimes[i+1]; if ( isSegmentBeginTime(frameBegin) ) { LocalDateTime auctionTime = frameBegin.minusMinutes(5); LocalDateTime marketBeforeOpenTime = auctionTime.minusMinutes(55); if ( time.isBefore(marketBeforeOpenTime) ){ return MarketTimeStage.MarketClose; } else { if ( time.isBefore(auctionTime) ) { return MarketTimeStage.BeforeMarketOpen; } else { if ( time.isBefore(frameBegin)){ return MarketTimeStage.AggregateAuction; } } } } else { if ( time.isBefore(frameBegin) ) { return MarketTimeStage.MarketBreak; } } if ( compareTimeNoNanos(time, frameBegin)>=0 && compareTimeNoNanos(time,frameEnd)<=0 ) { return MarketTimeStage.MarketOpen; } } return MarketTimeStage.MarketClose; }
Example 15
Source File: Helper.java From charts with Apache License 2.0 | 4 votes |
public static final LocalDateTime clamp(final LocalDateTime MIN, final LocalDateTime MAX, final LocalDateTime VALUE) { if (VALUE.isBefore(MIN)) return MIN; if (VALUE.isAfter(MAX)) return MAX; return VALUE; }
Example 16
Source File: OperatorController.java From OEE-Designer with MIT License | 4 votes |
private void setEventTimes(OeeEvent event, LocalDate startDate, String start, LocalDate endDate, String end, boolean forPeriod) throws Exception { // start time Duration startSeconds = null; if (start != null && start.trim().length() > 0) { startSeconds = AppUtils.durationFromString(start.trim()); } else { startSeconds = Duration.ZERO; } LocalTime startTime = LocalTime.ofSecondOfDay(startSeconds.getSeconds()); LocalDateTime ldtStart = LocalDateTime.of(startDate, startTime); event.setStartTime(DomainUtils.fromLocalDateTime(ldtStart)); // end time if (forPeriod) { Duration endSeconds = null; if (end != null && end.trim().length() > 0) { endSeconds = AppUtils.durationFromString(end.trim()); } else { endSeconds = Duration.ZERO; } LocalTime endTime = LocalTime.ofSecondOfDay(endSeconds.getSeconds()); LocalDateTime ldtEnd = LocalDateTime.of(endDate, endTime); if (ldtEnd.isBefore(ldtStart)) { throw new Exception(OperatorLocalizer.instance().getErrorString("invalid.start", ldtStart, ldtEnd)); } event.setEndTime(DomainUtils.fromLocalDateTime(ldtEnd)); } // get the shift from the work schedule WorkSchedule schedule = equipment.findWorkSchedule(); if (schedule != null) { List<ShiftInstance> shifts = schedule.getShiftInstancesForTime(ldtStart); if (!shifts.isEmpty()) { event.setShift(shifts.get(0).getShift()); event.setTeam(shifts.get(0).getTeam()); } } }
Example 17
Source File: PDTHelper.java From ph-commons with Apache License 2.0 | 4 votes |
@Nonnull public static LocalDateTime getMin (@Nonnull final LocalDateTime aDateTime1, @Nonnull final LocalDateTime aDateTime2) { return aDateTime1.isBefore (aDateTime2) ? aDateTime1 : aDateTime2; }
Example 18
Source File: TimerChecker.java From FX-AlgorithmTrading with MIT License | 4 votes |
/** * 指定時刻までタイマーを進めイベントを送信します 。主にバックテストで使用します。 * * @param updateDateTime 基準時刻 */ public void proceedTimer(LocalDateTime updateDateTime) { while (!updateDateTime.isBefore(nextDateTimeMap.get(SHORTEST_PERIOD))) { checkTime(updateDateTime); } }
Example 19
Source File: TimerChecker.java From FX-AlgorithmTrading with MIT License | 4 votes |
/** * TImerの更新をチェックします。 * * @param updateDateTime */ public synchronized void checkTime(LocalDateTime updateDateTime) { LocalDateTime nextDateTime1min = nextDateTimeMap.get(SHORTEST_PERIOD); // 最小更新間隔である1分の更新をチェックして、更新がなければ全部更新しない if (updateDateTime.isBefore(nextDateTime1min)) { return; } // Market Close 時間帯は更新しない if (!MarketTimeUtility.isMarketOpened(nextDateTime1min)) { // 次のOpen時刻まで進める putForwardTimeToNext(MarketTimeUtility.getNextOpenTime(nextDateTime1min)); return; } // 土曜日は Market Close 15分前に WEEK_ENDイベントを送信する if (!onWeekend && updateDateTime.getDayOfWeek() == DayOfWeek.SATURDAY) { LocalTime closeTime = MarketTimeUtility.getCloseWeekTimeSaturday(updateDateTime.toLocalDate()); if(!updateDateTime.toLocalTime().isBefore(closeTime.minusMinutes(WEEKEND_BEFORE_MINUTES))) { onWeekend = true; eventGenarator.sendWeekEndEvent(nextDateTime1min); } } else if (onWeekend && updateDateTime.getDayOfWeek() == DayOfWeek.MONDAY) { // 月曜はStart時刻に開始イベントを送信する LocalTime openTime = MarketTimeUtility.getOpenWeekTimeMonday(updateDateTime.toLocalDate()); if(!updateDateTime.toLocalTime().isBefore(openTime)) { onWeekend = false; eventGenarator.sendWeekStartEvent(nextDateTime1min); } } // 各基準時刻を進める for (Period period : TIMER_PERIODS) { LocalDateTime lastDateTime = lastDateTimeMap.get(period); LocalDateTime nextDateTime = nextDateTimeMap.get(period); // 5min以降の比較用 LocalDateTime lastDateTime1min = lastDateTimeMap.get(SHORTEST_PERIOD); // 現在時刻が次の更新予定時刻以降 if (!updateDateTime.isBefore(nextDateTime)) { // その時刻のMIN_1が更新されていなければ抜ける(先にMIN_1を更新する) if (period != SHORTEST_PERIOD && lastDateTime1min.isBefore(nextDateTime)) { return; } // 更新時刻、次回時刻を設定 lastDateTime = nextDateTime; if (period != Period.DAILY) { nextDateTime = nextDateTime.plus(period.getTimeInverval(), period.getChronoUnit()); } else { nextDateTime = culcurateNextDailyUpdate(nextDateTime.toLocalDate()); } sendTimerEvent(period, lastDateTime, nextDateTime); // LocalDateTime は immutable なので入れなおす lastDateTimeMap.put(period, lastDateTime); nextDateTimeMap.put(period, nextDateTime); } else { // 更新が無い場合、より長い時刻は更新しない return; } } }
Example 20
Source File: RangeOfLocalDateTimes.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(LocalDateTime value) { return ascend ? value.compareTo(start()) >=0 && value.isBefore(end()) : value.compareTo(start()) <=0 && value.isAfter(end()); }