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

The following examples show how to use java.time.ZonedDateTime#compareTo() . 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: ExpChartController.java    From logbook-kai with MIT License 6 votes vote down vote up
/**
 * グラフデータを読み込み
 * 
 * @param type 種類
 * @param scale 期間
 * @param min 期間の最小(自身を含む)
 * @param max 期間の最大(自身を含まない)
 * @return グラフデータ
 */
private Map<ZonedDateTime, Double> load(TypeOption type, ScaleOption scale, ZonedDateTime min, ZonedDateTime max) {
    Map<ZonedDateTime, Double> map = new LinkedHashMap<>();
    // 空のデータを作る
    ZonedDateTime current = min;
    while (current.compareTo(max) < 0) {
        map.put(current, 0D);
        current = current.plus(scale.getTick());
    }
    // ログから読み込み
    Instant minInstant = min.toInstant();
    Instant maxInstant = max.toInstant();

    List<SimpleBattleLog> logs = BattleLogs.readSimpleLog(log -> {
        Instant a = log.getDate().toInstant();
        return a.compareTo(minInstant) >= 0 && a.compareTo(maxInstant) < 0;
    });
    map.putAll(logs.stream()
            .collect(Collectors.groupingBy(log -> scale.convert(log.getDate(), type),
                    Collectors.summingDouble(type::convert))));
    return map;
}
 
Example 2
Source File: AppQuestCollection.java    From logbook-kai with MIT License 6 votes vote down vote up
/**
 * 任務を更新します
 */
public void update() {
    ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Asia/Tokyo"));

    val copyMap = new ConcurrentSkipListMap<>(this.quest);
    for (Iterator<Entry<Integer, AppQuest>> iterator = copyMap.entrySet().iterator(); iterator.hasNext();) {
        Entry<Integer, AppQuest> entry = iterator.next();

        String exp = entry.getValue().getExpire();
        if (exp != null) {
            TemporalAccessor ta = Logs.DATE_FORMAT.parse(exp);
            ZonedDateTime exptime = ZonedDateTime.of(LocalDateTime.from(ta), ZoneId.of("Asia/Tokyo"));
            // 期限切れを削除
            if (now.compareTo(exptime) > 0) {
                iterator.remove();
            }
        }
    }
    this.quest = copyMap;
}
 
Example 3
Source File: TaskUtil.java    From GriefDefender with MIT License 5 votes vote down vote up
public static ZonedDateTime getNextTargetZoneDate(int targetHour, int targetMin, int targetSec) {
    LocalDateTime localNow = LocalDateTime.now();
    ZoneId currentZone = ZoneId.systemDefault();
    ZonedDateTime zonedNow = ZonedDateTime.of(localNow, currentZone);
    ZonedDateTime zonedNextTarget = zonedNow.withHour(targetHour).withMinute(targetMin).withSecond(targetSec);
    if(zonedNow.compareTo(zonedNextTarget) > 0) {
        zonedNextTarget = zonedNextTarget.plusDays(1);
    }
    return zonedNextTarget;
}
 
Example 4
Source File: TaskUtil.java    From GriefDefender with MIT License 5 votes vote down vote up
public static ZonedDateTime getNextTargetZoneDate(int targetHour, int targetMin, int targetSec) {
    LocalDateTime localNow = LocalDateTime.now();
    ZoneId currentZone = ZoneId.systemDefault();
    ZonedDateTime zonedNow = ZonedDateTime.of(localNow, currentZone);
    ZonedDateTime zonedNextTarget = zonedNow.withHour(targetHour).withMinute(targetMin).withSecond(targetSec);
    if(zonedNow.compareTo(zonedNextTarget) > 0) {
        zonedNextTarget = zonedNextTarget.plusDays(1);
    }
    return zonedNextTarget;
}
 
Example 5
Source File: ContentComparatorBase.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * compare dates
 * 
 * @param value1
 * @param value2
 * @param ascending
 * @return sorting result
 */
protected int compareDates(ZonedDateTime value1, ZonedDateTime value2, boolean ascending) {
	if (value1 == null && value2 == null) {
		return 0;
	} else if (value1 == null) {
		return (_ascending) ? -1 : 1;
	} else if (value2 == null) {
		return (_ascending) ? 1 : -1;
	} else if (_ascending) {
		return value1.compareTo(value2);
	} else {
		return value1.compareTo(value2) * -1;
	}
}
 
Example 6
Source File: TaskUtil.java    From GriefDefender with MIT License 5 votes vote down vote up
public static long computeDelay(int targetHour, int targetMin, int targetSec) 
{
    LocalDateTime localNow = LocalDateTime.now();
    ZoneId currentZone = ZoneId.systemDefault();
    ZonedDateTime zonedNow = ZonedDateTime.of(localNow, currentZone);
    ZonedDateTime zonedNextTarget = zonedNow.withHour(targetHour).withMinute(targetMin).withSecond(targetSec);
    if(zonedNow.compareTo(zonedNextTarget) > 0) {
        zonedNextTarget = zonedNextTarget.plusDays(1);
    }

    Duration duration = Duration.between(zonedNow, zonedNextTarget);
    return duration.getSeconds();
}
 
Example 7
Source File: JpaControllerManagement.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This method calculates the time interval until the next event based on the
 * desired number of events before the time when interval is reset to default.
 * The return value is bounded by {@link EventTimer#defaultEventInterval} and
 * {@link EventTimer#minimumEventInterval}.
 *
 * @param eventCount
 *            number of events desired until the interval is reset to default.
 *            This is not guaranteed as the interval between events cannot be
 *            less than the minimum interval
 * @param timerResetTime
 *            time when exponential forwarding should reset to default
 *
 * @return String in HH:mm:ss format for time to next event.
 */
String timeToNextEvent(final int eventCount, final ZonedDateTime timerResetTime) {
    final ZonedDateTime currentTime = ZonedDateTime.now();

    // If there is no reset time, or if we already past the reset time,
    // return the default interval.
    if (timerResetTime == null || currentTime.compareTo(timerResetTime) > 0) {
        return defaultEventInterval;
    }

    // Calculate the interval timer based on desired event count.
    final Duration currentIntervalDuration = Duration.of(currentTime.until(timerResetTime, timeUnit), timeUnit)
            .dividedBy(eventCount);

    // Need not return interval greater than the default.
    if (currentIntervalDuration.compareTo(defaultEventIntervalDuration) > 0) {
        return defaultEventInterval;
    }

    // Should not return interval less than minimum.
    if (currentIntervalDuration.compareTo(minimumEventIntervalDuration) < 0) {
        return minimumEventInterval;
    }

    return String.format("%02d:%02d:%02d", currentIntervalDuration.toHours(),
            currentIntervalDuration.toMinutes() % 60, currentIntervalDuration.getSeconds() % 60);
}
 
Example 8
Source File: TimerExecutor.java    From TelegramApi with MIT License 5 votes vote down vote up
/**
 * Find out next with time offset
 *
 * @param hourOffset hour offset
 * @param minOffset  minute offset
 * @param secOffset  second offset
 * @return time in second to wait
 * @note It will add one minute extra until next time is bigger than target time
 */
private long computNextTime(int hourOffset, int minOffset, int secOffset) {
    final LocalDateTime localNow = LocalDateTime.now();
    final ZoneId currentZone = ZoneId.systemDefault();
    final ZonedDateTime zonedNow = ZonedDateTime.of(localNow, currentZone);
    ZonedDateTime zonedNextTarget = zonedNow.plusHours(hourOffset)
            .plusMinutes(minOffset).plusSeconds(secOffset);
    while (zonedNow.compareTo(zonedNextTarget) > 0) {
        zonedNextTarget = zonedNextTarget.plusSeconds(5);
    }

    final Duration duration = Duration.between(zonedNow, zonedNextTarget);
    return duration.getSeconds();
}
 
Example 9
Source File: TimerExecutor.java    From TelegramApi with MIT License 5 votes vote down vote up
/**
 * 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();
    final ZoneId currentZone = ZoneId.systemDefault();
    final ZonedDateTime zonedNow = ZonedDateTime.of(localNow, currentZone);
    ZonedDateTime zonedNextTarget = zonedNow.withHour(targetHour).withMinute(targetMin).withSecond(targetSec);
    while (zonedNow.compareTo(zonedNextTarget) > 0) {
        zonedNextTarget = zonedNextTarget.plusDays(1);
    }

    final Duration duration = Duration.between(zonedNow, zonedNextTarget);
    return duration.getSeconds();
}
 
Example 10
Source File: NationsPlugin.java    From Nations with MIT License 4 votes vote down vote up
@Listener
public void onStart(GameStartedServerEvent event)
{
	LanguageHandler.load();
	ConfigHandler.load();
	DataHandler.load();
	
	Sponge.getServiceManager()
			.getRegistration(EconomyService.class)
			.ifPresent(prov -> economyService = prov.getProvider());


	NationCmds.create(this);

	Sponge.getEventManager().registerListeners(this, new PlayerConnectionListener());
	Sponge.getEventManager().registerListeners(this, new PlayerMoveListener());
	Sponge.getEventManager().registerListeners(this, new GoldenAxeListener());
	Sponge.getEventManager().registerListeners(this, new PvpListener());
	Sponge.getEventManager().registerListeners(this, new FireListener());
	Sponge.getEventManager().registerListeners(this, new ExplosionListener());
	Sponge.getEventManager().registerListeners(this, new MobSpawningListener());
	Sponge.getEventManager().registerListeners(this, new BuildPermListener());
	Sponge.getEventManager().registerListeners(this, new InteractPermListener());
	Sponge.getEventManager().registerListeners(this, new ChatListener());

	LocalDateTime localNow = LocalDateTime.now();
	ZonedDateTime zonedNow = ZonedDateTime.of(localNow, ZoneId.systemDefault());
	ZonedDateTime zonedNext = zonedNow.withHour(12).withMinute(0).withSecond(0);
	if (zonedNow.compareTo(zonedNext) > 0)
		zonedNext = zonedNext.plusDays(1);
	long initalDelay = Duration.between(zonedNow, zonedNext).getSeconds();

	Sponge.getScheduler()
			.createTaskBuilder()
			.execute(new TaxesCollectRunnable())
			.delay(initalDelay, TimeUnit.SECONDS)
			.interval(1, TimeUnit.DAYS)
			.async()
			.submit(this);

	logger.info("Plugin ready");
}
 
Example 11
Source File: TCKZonedDateTime.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_compareTo_null() {
    ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);
    a.compareTo(null);
}
 
Example 12
Source File: GenerateSeries.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public Iterable<Row> evaluate(TransactionContext txnCtx, Input<Object>... args) {
    Long startInclusive = (Long) args[0].value();
    Long stopInclusive = (Long) args[1].value();
    Period step = (Period) args[2].value();
    if (startInclusive == null || stopInclusive == null || step == null) {
        return Bucket.EMPTY;
    }
    ZonedDateTime start = Instant.ofEpochMilli(startInclusive).atZone(ZoneOffset.UTC);
    ZonedDateTime stop = Instant.ofEpochMilli(stopInclusive).atZone(ZoneOffset.UTC);
    boolean reverse = start.compareTo(stop) > 0;
    if (reverse && add(start, step).compareTo(start) >= 0) {
        return Bucket.EMPTY;
    }
    return () -> new Iterator<>() {

        final Object[] cells = new Object[1];
        final RowN rowN = new RowN(cells);

        ZonedDateTime value = start;
        boolean doStep = false;

        @Override
        public boolean hasNext() {
            if (doStep) {
                value = add(value, step);
                doStep = false;
            }
            int compare = value.compareTo(stop);
            return reverse
                ? compare >= 0
                : compare <= 0;
        }

        @Override
        public Row next() {
            if (!hasNext()) {
                throw new NoSuchElementException("No more element in generate_series");
            }
            doStep = true;
            cells[0] = (value.toEpochSecond() * 1000);
            return rowN;
        }
    };
}
 
Example 13
Source File: TCKZonedDateTime.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=NullPointerException.class)
public void test_compareTo_null() {
    ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);
    a.compareTo(null);
}
 
Example 14
Source File: TCKZonedDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_compareTo_null() {
    ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);
    a.compareTo(null);
}
 
Example 15
Source File: TCKZonedDateTime.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_compareTo_null() {
    ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);
    a.compareTo(null);
}
 
Example 16
Source File: TCKZonedDateTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_compareTo_null() {
    ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);
    a.compareTo(null);
}
 
Example 17
Source File: TCKZonedDateTime.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_compareTo_null() {
    ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);
    a.compareTo(null);
}
 
Example 18
Source File: TCKZonedDateTime.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_compareTo_null() {
    ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);
    a.compareTo(null);
}
 
Example 19
Source File: TCKZonedDateTime.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_compareTo_null() {
    ZonedDateTime a = ZonedDateTime.of(2008, 6, 30, 23, 30, 59, 0, ZONE_0100);
    a.compareTo(null);
}
 
Example 20
Source File: RangeOfZonedDateTimes.java    From morpheus-core with Apache License 2.0 3 votes vote down vote up
/**
 * 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
 */
RangeOfZonedDateTimes(ZonedDateTime start, ZonedDateTime end, Duration step, Predicate<ZonedDateTime> excludes) {
    super(start, end);
    this.step = step;
    this.ascend = start.compareTo(end) <= 0;
    this.excludes = excludes;
}