Java Code Examples for java.time.LocalDateTime#isBefore()

The following examples show how to use java.time.LocalDateTime#isBefore() . These examples are extracted from open source projects. 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 Project: FX-AlgorithmTrading   File: TimerChecker.java    License: MIT License 6 votes vote down vote up
/**
 * すべてのスケールの基準時刻を指定時間まで進めます
 * @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 Project: j2objc   File: ZoneRules.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 Project: JDKSourceCode1.8   File: ZoneRules.java    License: MIT License 6 votes vote down vote up
/**
 * 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 Project: Bytecoder   File: ZoneRules.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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
@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 6
Source Project: yes-cart   File: DomainApiUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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
/**
 * 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 8
/**
 * 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 Project: jdk8u60   File: ZoneRules.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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
/**
 * 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 Project: cucumber-performance   File: Errors.java    License: MIT License 5 votes vote down vote up
public void update(LocalDateTime date) {
	if (date.isBefore(first))
		first = date;
	if (date.isAfter(last))
		last = date;
	incrementCount();
}
 
Example 12
@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
/**
 * 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
/**
 * 市场时间段
 */
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 Project: FX-AlgorithmTrading   File: TimerChecker.java    License: MIT License 4 votes vote down vote up
/**
 * 指定時刻までタイマーを進めイベントを送信します 。主にバックテストで使用します。
 *
 * @param updateDateTime 基準時刻
 */
public void proceedTimer(LocalDateTime updateDateTime) {
    while (!updateDateTime.isBefore(nextDateTimeMap.get(SHORTEST_PERIOD))) {
        checkTime(updateDateTime);
    }
}
 
Example 16
Source Project: charts   File: Helper.java    License: Apache License 2.0 4 votes vote down vote up
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 17
Source Project: OEE-Designer   File: OperatorController.java    License: MIT License 4 votes vote down vote up
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 18
Source Project: ph-commons   File: PDTHelper.java    License: Apache License 2.0 4 votes vote down vote up
@Nonnull
public static LocalDateTime getMin (@Nonnull final LocalDateTime aDateTime1, @Nonnull final LocalDateTime aDateTime2)
{
  return aDateTime1.isBefore (aDateTime2) ? aDateTime1 : aDateTime2;
}
 
Example 19
Source Project: FX-AlgorithmTrading   File: TimerChecker.java    License: MIT License 4 votes vote down vote up
/**
 * 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
/**
 * 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());
}