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

The following examples show how to use java.time.LocalDateTime#compareTo() . 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
private static LocalDateTime reconcileCreationDate(LocalDateTime lastNonSelfUpdate,
                                                   LocalDateTime creationTime,
                                                   String currentUser,
                                                   String issueCreator) {
    // If current user is same as issue creator, we do not consider creation of issue
    // as an issue update.
    if (currentUser.equalsIgnoreCase(issueCreator)) return lastNonSelfUpdate;

    // Current user is not the issue creator.
    // lastNonSelfUpdate cannot be before creationTime unless it is the default value (epoch 0),
    // which means the issue has no events or comments.
    // However, since the current user is not the issue creator, creation of the issue itself
    // counts as an update.
    if (lastNonSelfUpdate.compareTo(creationTime) < 0) return creationTime;

    // Otherwise, the issue actually possesses non-self updates, so we do nothing with the
    // value.
    return lastNonSelfUpdate;
}
 
Example 2
/**
 * Schedule background execution of media library scanning.
 */
public synchronized void schedule() {
    if (scheduler != null) {
        scheduler.shutdown();
    }

    long daysBetween = settingsService.getIndexCreationInterval();
    int hour = settingsService.getIndexCreationHour();

    if (daysBetween == -1) {
        LOG.info("Automatic media scanning disabled.");
        return;
    }

    scheduler = Executors.newSingleThreadScheduledExecutor();

    LocalDateTime now = LocalDateTime.now();
    LocalDateTime nextRun = now.withHour(hour).withMinute(0).withSecond(0);
    if (now.compareTo(nextRun) > 0)
        nextRun = nextRun.plusDays(1);

    long initialDelay = ChronoUnit.MILLIS.between(now, nextRun);

    scheduler.scheduleAtFixedRate(() -> scanLibrary(), initialDelay, TimeUnit.DAYS.toMillis(daysBetween), TimeUnit.MILLISECONDS);

    LOG.info("Automatic media library scanning scheduled to run every {} day(s), starting at {}", daysBetween, nextRun);

    // In addition, create index immediately if it doesn't exist on disk.
    if (neverScanned()) {
        LOG.info("Media library never scanned. Doing it now.");
        scanLibrary();
    }
}
 
Example 3
Source Project: java-trader   File: LeveledBarSeries.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 返回当天(交易日)的序列数据, 清除历史数据
 */
public static LeveledBarSeries getDailySeries(LocalDate tradingDay, LeveledBarSeries series, boolean includeLast) {
    Exchangeable e = series.getExchangeable();
    ExchangeableTradingTimes tradingTimes =  e.exchange().getTradingTimes(e, tradingDay);
    LocalDateTime mktOpenTime = tradingTimes.getMarketOpenTime();
    LocalDateTime mktCloseTime = tradingTimes.getMarketCloseTime();
    int beginIndex = -1; //inclusive
    int endIndex = -1; //exclusive
    int currIndex=series.getBeginIndex();

    while(currIndex<=series.getEndIndex()) {
        Bar2 bar = (Bar2)series.getBar(currIndex);
        if ( beginIndex<0 && mktOpenTime.compareTo(bar.getBeginTime().toLocalDateTime())<=0 ) {
            beginIndex = currIndex;
            endIndex = beginIndex+1;
        } else if ( beginIndex>=0 && mktCloseTime.compareTo(bar.getEndTime().toLocalDateTime().withNano(0))>=0 ) {
            endIndex = currIndex+1;
        } else {
            if ( endIndex>0 ) {
                break;
            }
        }
        currIndex++;
    }

    if ( !includeLast ) {
        endIndex--;
    }
    return (LeveledBarSeries)series.getSubSeries(beginIndex, endIndex);
}
 
Example 4
/**
 * 返回当前的市场分段(日市/夜市)
 */
public MarketType getSegmentType(LocalDateTime time) {
    for(MarketTimeSegmentInfo segInfo: this.segmentInfos) {
        LocalDateTime beginTime = segInfo.marketTimes[0].minusHours(1);
        LocalDateTime endTime = segInfo.marketTimes[segInfo.marketTimes.length-1];
        if ( time.compareTo(beginTime)>=0 && time.compareTo(endTime)<=0 ) {
            return segInfo.segment.marketType;
        }
    }
    return null;
}
 
Example 5
/**
 * Schedule background execution of media library scanning.
 */
public synchronized void schedule() {
    if (scheduler != null) {
        scheduler.shutdown();
    }

    long daysBetween = settingsService.getIndexCreationInterval();
    int hour = settingsService.getIndexCreationHour();

    if (daysBetween == -1) {
        LOG.info("Automatic media scanning disabled.");
        return;
    }

    scheduler = Executors.newSingleThreadScheduledExecutor();

    LocalDateTime now = LocalDateTime.now();
    LocalDateTime nextRun = now.withHour(hour).withMinute(0).withSecond(0);
    if (now.compareTo(nextRun) > 0)
        nextRun = nextRun.plusDays(1);

    long initialDelay = ChronoUnit.MILLIS.between(now, nextRun);

    scheduler.scheduleAtFixedRate(() -> scanLibrary(), initialDelay, TimeUnit.DAYS.toMillis(daysBetween), TimeUnit.MILLISECONDS);

    LOG.info("Automatic media library scanning scheduled to run every {} day(s), starting at {}", daysBetween, nextRun);

    // In addition, create index immediately if it doesn't exist on disk.
    if (neverScanned()) {
        LOG.info("Media library never scanned. Doing it now.");
        scanLibrary();
    }
}
 
Example 6
/**
 * Find out next daily execution
 *
 * @param targetHour Target hour
 * @param targetMin  Target minute
 * @param targetSec  Target second
 * @return time in second to wait
 */
private long computNextDilay(int targetHour, int targetMin, int targetSec) {
    final LocalDateTime localNow = LocalDateTime.now(Clock.systemUTC());
    LocalDateTime localNextTarget = localNow.withHour(targetHour).withMinute(targetMin).withSecond(targetSec);
    while (localNow.compareTo(localNextTarget.minusSeconds(1)) > 0) {
        localNextTarget = localNextTarget.plusDays(1);
    }

    final Duration duration = Duration.between(localNow, localNextTarget);
    return duration.getSeconds();
}
 
Example 7
@Override
public int compareTo(Study s) {
    LocalDateTime date1 =
        DateUtil.dateTime(DateUtil.getDicomDate(getStudyDate()), DateUtil.getDicomTime(getStudyTime()));
    LocalDateTime date2 =
        DateUtil.dateTime(DateUtil.getDicomDate(s.getStudyDate()), DateUtil.getDicomTime(s.getStudyTime()));

    int c = -1;
    if (date1 != null && date2 != null) {
        // inverse time
        c = date2.compareTo(date1);
        if (c != 0) {
            return c;
        }
    }

    if (c == 0 || (date1 == null && date2 == null)) {
        String d1 = getStudyDescription();
        String d2 = s.getStudyDescription();
        if (d1 != null && d2 != null) {
            c = Collator.getInstance(Locale.getDefault()).compare(d1, d2);
            if (c != 0) {
                return c;
            }
        }
        if (d1 == null) {
            // Add o1 after o2
            return d2 == null ? 0 : 1;
        }
        // Add o2 after o1
        return -1;
    } else {
        if (date1 == null) {
            // Add o1 after o2
            return 1;
        }
        return -1;
    }
}
 
Example 8
@Override
public int compare(Object o1, Object o2) {
    try {
        LocalDateTime createTime1 = (LocalDateTime) PropertyUtils.getProperty(o1, "createdtime");
        LocalDateTime createTime2 = (LocalDateTime) PropertyUtils.getProperty(o2, "createdtime");
        return createTime1.compareTo(createTime2);
    } catch (Exception e) {
        return 0;
    }
}
 
Example 9
@Override
public int compare(Object o1, Object o2) {
    try {
        LocalDateTime createTime1 = (LocalDateTime) PropertyUtils.getProperty(o1, "createdtime");
        LocalDateTime createTime2 = (LocalDateTime) PropertyUtils.getProperty(o2, "createdtime");
        return createTime1.compareTo(createTime2);
    } catch (Exception e) {
        return 0;
    }
}
 
Example 10
@Override
public int compare(Viewer viewer, Object e1, Object e2){
	IFinding p1 = (IFinding) e1;
	IFinding p2 = (IFinding) e2;
	int rc = 0;
	switch (propertyIndex) {
	case 0:
	case 1:
		LocalDateTime t1 = LocalDateTime.MIN;
		LocalDateTime t2 = LocalDateTime.MIN;
		if (p1 instanceof IObservation) {
			t1 = ((IObservation) p1).getEffectiveTime().orElse(LocalDateTime.MIN);
		}
		if (p2 instanceof IObservation) {
			t2 = ((IObservation) p2).getEffectiveTime().orElse(LocalDateTime.MIN);
		}
		rc = t1.compareTo(t2);
		break;
	case 2:
		String txt1 = p1.getText().orElse("");
		String txt2 = p2.getText().orElse("");
		rc = txt1.toLowerCase().compareTo(txt2.toLowerCase());
		break;
	default:
		rc = 0;
	}
	// If descending order, flip the direction
	if (direction == DESCENDING) {
		rc = -rc;
	}
	return rc;
}
 
Example 11
Source Project: flink   File: LocalDateTimeComparator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public int compare(LocalDateTime first, LocalDateTime second) {
	int cmp = first.compareTo(second);
	return ascendingComparison ? cmp : -cmp;
}
 
Example 12
Source Project: java-trader   File: BarSeriesLoader.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 根据时间返回当前KBar序列的位置
 * @return -1 如果未开市, 0-N
 */
public static int getBarIndex(ExchangeableTradingTimes tradingTimes, PriceLevel level, LocalDateTime marketTime)
{
    if( level==PriceLevel.DAY ){
        return 0;
    }
    if ( tradingTimes==null ) {
        return -1;
    }
    MarketTimeStage mts = tradingTimes.getTimeStage(marketTime);
    switch(mts){
    case AggregateAuction:
    case BeforeMarketOpen:
        return -1;
    case MarketOpen:
    case MarketBreak:
        break;
    default:
        return -1;
    }

    int tradingMillis = tradingTimes.getTradingTime(marketTime);
    int tradeMinutes = tradingMillis / (1000*60);
    int tickIndex=0;

    LocalDateTime[] marketTimes = tradingTimes.getMarketTimes();
    for(int i=0;i<marketTimes.length;i+=2) {
        LocalDateTime stageBegin = marketTimes[i];
        LocalDateTime stageEnd = marketTimes[i+1];
        LocalDateTime stageBegin2 = null;
        if ( i<marketTimes.length-2) {
            stageBegin2 = marketTimes[i+2];
        }
        //如果已经是下一个时间段, 直接跳过当前时间段
        if ( stageBegin2!=null && marketTime.compareTo(stageBegin2)>=0 ) {
            continue;
        }
        if ( marketTime.compareTo(stageBegin)<0 ) {
            break;
        }
        int compareResult = marketTime.compareTo(stageEnd);
        tickIndex = tradeMinutes/level.value();
        int tickBeginMillis = tickIndex*level.value()*60*1000;
        if ( compareResult>=0 ) {
            //超过当前时间段, 但是没有到下一个时间段, 算在最后一个KBar
            if ( tradingMillis-tickBeginMillis<5*1000 ) {
                tickIndex -= 1;
            }
        }
        break;
    }

    return tickIndex;
}
 
Example 13
Source Project: tablesaw   File: DateTimeColumn.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public int compare(LocalDateTime o1, LocalDateTime o2) {
  return o1.compareTo(o2);
}
 
Example 14
@Override
public synchronized void changePeriod(TimerInformation timerInformation) {
    Period period = timerInformation.getPeriod();
    LocalDateTime baseDateTime = timerInformation.getCurrentDateTime();
    LocalDateTime nextDateTime = timerInformation.getNextDateTime();

    // logger.debug("Timer updated {}. Current = {}, Next = {}", period, baseDateTime, nextDateTime);
    if (!indicatorPeriodTimes.contains(period)) {
        // logger.debug("Skip calculate indicators. Period = {}", period.name());
        return;
    }

    // 対象より短いPeriodが更新されているか確認、更新されていない場合はwaitする
    if (period != shortestTimePeriod) {
        Period shorterPeriod = period.getShorterPeriod(indicatorPeriodTimes);
        LocalDateTime shorterUpdateTIme = lastUpdateTimeMap.get(shorterPeriod);
        if (shorterUpdateTIme.compareTo(baseDateTime) < 0) {
            logger.warn("Shorter period has not updated yet. Period = {}, Time = {}", shorterPeriod, shorterUpdateTIme);
            waitingUpdateMap.put(period, timerInformation);
            return;
        }
    }

    // Periodごとの更新時刻の更新
    lastUpdateTimeMap.put(period, baseDateTime);

    for (Symbol symbol : latestOHLCMap.keySet()) {
        // 最新データを次の期間に更新して、最新データ取得
        OHLC ohlc = latestOHLCMap.get(symbol).moveNextDateTime(period, nextDateTime);

        // 初回の更新は時刻がnullなので抜ける
        if (ohlc.getBaseDateTime() == null) {
            logger.debug("First update of OHLC for Period = {}, Symbol = {}", period, symbol);
            continue;
        }

        // 1度も更新が無い場合は前回のCloseを使用する
        if (!ohlc.isInitialized()) {
            // logger.debug("Skip indicator update. No market update, and OHLC is NOT initialized. DateTime = {}, Period = {}, Symbol = {}", ohlc.getBaseDateTime(), period, symbol);
            OHLC lastOHLC = ohlcMap.getIndicator(symbol, period).getLastOHLC();
            if (lastOHLC == null) {
                continue;
            }
            ohlc.update(lastOHLC.getCloseBid(), lastOHLC.getCloseAsk());
        }

        // Notify to Indicators
        updateOHLCAndIndicators(symbol, period, ohlc);
    }

    // 更新待ち確認
    if (!waitingUpdateMap.isEmpty()) {
        for (TimerInformation waitingTimer : waitingUpdateMap.values()) {
            logger.warn("Waiting Update, Period = {}, time = {}", waitingTimer.getPeriod(), waitingTimer.getCurrentDateTime());
            if (waitingTimer.getPeriod().getOrder() > period.getOrder() && !baseDateTime.isBefore(waitingTimer.getCurrentDateTime())) {
                changePeriod(waitingTimer);
            }
        }
    }
}
 
Example 15
Source Project: tablesaw   File: DateTimeColumn.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public int compare(LocalDateTime o1, LocalDateTime o2) {
  return o1.compareTo(o2);
}
 
Example 16
Source Project: flink   File: LocalDateTimeComparator.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public int compare(LocalDateTime first, LocalDateTime second) {
	int cmp = first.compareTo(second);
	return ascendingComparison ? cmp : -cmp;
}
 
Example 17
/** Interface Comparable, um die Behandlungen nach Datum und Zeit sortieren zu können */
public int compareTo(Konsultation b){
	LocalDateTime me = getDateTime();
	LocalDateTime other = b.getDateTime();
	return me.compareTo(other);
}
 
Example 18
/**
 * Constructor
 * @param start     the start for range, inclusive
 * @param end       the end for range, exclusive
 * @param step      the step increment
 * @param excludes  optional predicate to exclude elements in this range
 */
RangeOfLocalDateTimes(LocalDateTime start, LocalDateTime end, Duration step, Predicate<LocalDateTime> excludes) {
    super(start, end);
    this.step = step;
    this.ascend = start.compareTo(end) <= 0;
    this.excludes = excludes;
}
 
Example 19
/**
 * 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());
}