public static long getCostMS(Instant start) { return Duration.between(start, Instant.now()).toMillis(); }
public static long getCostMS(Instant start) { return Duration.between(start, Instant.now()).toMillis(); }
double getTickProgress() { long timeSinceLastTick = Duration.between(startOfLastTick, Instant.now()).toMillis(); float tickProgress = (timeSinceLastTick % 600) / 600f; return tickProgress * Math.PI; }
@Override public String getText() { Duration timeLeft = Duration.between(Instant.now(), endTime); int seconds = (int) (timeLeft.toMillis() / 1000L); int minutes = (seconds % 3600) / 60; int secs = seconds % 60; return String.format("%d:%02d", minutes, secs); }
private void updatePing(EntityRef entity) { if (startMap.containsKey(entity) && endMap.containsKey(entity)) { long pingTime = Duration.between(startMap.get(entity), endMap.get(entity)).toMillis(); pingMap.put(entity, pingTime); } }
/** * Captures the time since last lap or creation, and resets the start time. * * @return the duration of the last lap, or since creation */ Duration lap() { Instant now = clock.instant(); Duration duration = Duration.between(lapStartTime, now); lapStartTime = now; return duration; }
/** * Gets the total elapsed time since creation. * * @return the total elapsed time */ Duration getElapsedTime() { return Duration.between(startTime, clock.instant()); } }
public Duration elapsed() { if (null == start) { return Duration.ZERO; } final Instant stopTime = (null==stop? times.getTime() : stop); return Duration.between(start, stopTime); }
private static void exec(Connection cxn, Migration migration) throws SQLException { cxn.setAutoCommit(false); try { Instant start = Instant.now(); migration.run(cxn); cxn.commit(); LOGGER.info("Data migration took {} ms", Duration.between(start, Instant.now()).toMillis()); } catch (SQLException e) { LOGGER.error("Data migration failed: {}", e.getMessage(), e); cxn.rollback(); throw e; } }
public Duration elapsed() { if (null == start) { return Duration.ZERO; } final Instant stopTime = (null==stop? times.getTime() : stop); return Duration.between(start, stopTime); }
@Override public boolean render() { Duration timeLeft = Duration.between(Instant.now(), endTime); return !timeLeft.isNegative(); }
/** * Calculates how much time is left before the trap is collapsing. * * @return Value between 0 and 1. 0 means the trap was laid moments ago. * 1 is a trap that's about to collapse. */ public double getTrapTimeRelative() { Duration duration = Duration.between(placedOn, Instant.now()); return duration.compareTo(TRAP_TIME) < 0 ? (double) duration.toMillis() / TRAP_TIME.toMillis() : 1; }
/** * Refresh all the metric value and the bindingMap who notes user's authorization. */ private void refreshMetricsPeriodic() { if (Duration.between(timeForRefreshMetric, Instant.now()).getSeconds() > 5) { metrics.refreshAllMetrics(); timeForRefreshMetric = Instant.now(); if (bindingMap != null) { refreshBindingMap(); } } }
private void recordPlayTime() { float playTime = Duration.between(lastRecordTime, Instant.now()).toMillis() / 1000f / 60; gamePlayStatsComponent.playTimeMinute += playTime; localPlayer.getCharacterEntity().addOrSaveComponent(gamePlayStatsComponent); lastRecordTime = Instant.now(); }
private void writeObject(java.io.ObjectOutputStream out) throws IOException { Instant creationTime = this.metaData.getCreationTime(); Duration maxInactiveInterval = this.metaData.getMaxInactiveInterval(); Duration lastAccessedDuration = Duration.between(creationTime, this.metaData.getLastAccessedTime()); out.defaultWriteObject(); out.writeObject(creationTime); out.writeObject(maxInactiveInterval); out.writeObject(lastAccessedDuration); }
private Duration timeSinceFirstMsg() { Duration sinceFirst = Duration.ZERO; if (!toSend.isEmpty()) { Instant firstTimestamp = toSend.get(0).message.getMessage().getTimestamp(); Instant nowTimestamp = times.getTime(); if (firstTimestamp.compareTo(nowTimestamp) < 0) { sinceFirst = Duration.between(firstTimestamp, nowTimestamp); } } return sinceFirst; }
private static SnapshotDto findNearestSnapshotToTargetDate(List<SnapshotDto> snapshots, Instant targetDate) { // FIXME shouldn't this be the first analysis after targetDate? Duration bestDuration = null; SnapshotDto nearest = null; for (SnapshotDto snapshot : snapshots) { Instant createdAt = Instant.ofEpochMilli(snapshot.getCreatedAt()); Duration duration = Duration.between(targetDate, createdAt).abs(); if (bestDuration == null || duration.compareTo(bestDuration) <= 0) { bestDuration = duration; nearest = snapshot; } } return nearest; }
private Duration timeSinceFirstMsg() { Duration sinceFirst = Duration.ZERO; if (!toSend.isEmpty()) { Instant firstTimestamp = toSend.get(0).message.getMessage().getTimestamp(); Instant nowTimestamp = times.getTime(); if (firstTimestamp.compareTo(nowTimestamp) < 0) { sinceFirst = Duration.between(firstTimestamp, nowTimestamp); } } return sinceFirst; }
public static String elapsedTime(Date d1, Date d2){ try{ Duration period = Duration.between(d1.toInstant(), d2.toInstant()); // Note: this will become easier with Java 9, using toDaysPart() etc. long days = period.toDays(); period = period.minusDays(days); long hours = period.toHours(); period = period.minusHours(hours); long minutes = period.toMinutes(); period = period.minusMinutes(minutes); long seconds = period.getSeconds(); return days + " days, " + hours + " hours, " + minutes + " minutes, " + seconds + " seconds"; } catch(java.lang.IllegalArgumentException e) { log.warn(e); } return ""; }
@Override public boolean render() { final boolean rendered = super.render(); if (rendered) { final Duration fromStart = Duration.between(getStartTime(), Instant.now()); return !fromStart.minus(timer.getInitialDelay()).isNegative(); } return false; }