boolean isThisRealtimeUpdateAboutThisLineRun(EdgeIteratorState edge, Instant now) { if (Duration.between(feedTimestampOrNow(), now).toHours() > 24) { return false; } else { return true; } }
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 ""; }
long hours = Duration.ofMillis(timeZone.getRawOffset()).toHours(); long millis = Duration.ofHours(hours).toMillis(); if (millis == timeZone.getRawOffset()) {
long hours = p.toHours() % 24; long minutes = p.toMinutes() % 60; long seconds = p.getSeconds() % 60;
@Override public Argument build(Duration duration, ConfigRegistry config) { Duration d = duration; final boolean isNegative = d.isNegative(); if (isNegative) { d = d.negated(); } final long days = d.toDays(); if (days > Integer.MAX_VALUE) { throw new IllegalArgumentException( String.format("duration %s too large to be represented unambiguously as postgres interval", d)); } d = d.minusDays(days); final int hours = (int) d.toHours(); d = d.minusHours(hours); final int minutes = (int) d.toMinutes(); d = d.minusMinutes(minutes); if (d.getNano() % 1000 != 0) { throw new IllegalArgumentException( String.format("duration %s too precise to represented as postgres interval", d)); } double seconds = d.getSeconds() + d.getNano() / 1e9; final PGInterval interval = new PGInterval(0, 0, (int) days, hours, minutes, seconds); if (isNegative) { interval.scale(-1); } return ObjectArgument.of(interval, Types.OTHER); } }
System.out.println("Duration in hours: " + duration.toHours());
.toHours(); long duration = Math.max(t.getDuration().toMinutes(), 0); transitionsList.add(epochHours);
/** Clone of java 9 {@code duration.toHoursPart()} to allow support until we update to above java 8. */ private static int toHoursPart(Duration duration) { return (int) (duration.toHours() % 24); }
private String formatRuntime(OffsetDateTime started, OffsetDateTime stopped) { Duration duration = Duration.between(started, stopped); if (duration.toHours() >= 24) { return "> 24h"; } LocalTime dateTime = LocalTime.ofSecondOfDay(duration.getSeconds()); return humanReadable ? ofPattern("HH:mm:ss").format(dateTime) : ofPattern("HH:mm:ss").format(dateTime); }
java.time.Duration duration = java.time.Duration.ofMinutes(67); LocalTime time = LocalTime.of((int) duration.toHours(), (int) duration.toMinutes() % 60); System.out.println("time = " + time); //01:07
public long findFreeHoursBetweenMeetings(String firstMeetingTitle, String secondMeetingTitle) { Meeting firstMeeting = meetings.get(firstMeetingTitle); Meeting secondMeeting = meetings.get(secondMeetingTitle); Duration duration = Duration.between(firstMeeting.getEnd(), secondMeeting.getStart()); return duration.toHours(); }
@Nonnull public String format (final @Nonnull Duration duration) { final long hours = duration.toHours(); final long minutes = duration.minusHours(hours).toMinutes(); return String.format("%d:%02d", hours, minutes); } }
private static String formatTime(long timeInMilliseconds) { Duration duration = Duration.ofMillis(timeInMilliseconds); long days = duration.toDays(); long hours = duration.minusDays(days).toHours(); long minutes = duration.minusHours(duration.toHours()).toMinutes(); return format("%dd %dh %dm", days, hours, minutes); }
public boolean hasIntervalEnded(RateLimit rate) { switch (rate.getInterval()) { case SECONDS: return Duration.between(LocalDateTime.now(), rate.getLastRequest()).getSeconds() > 0; case MINUTES: return Duration.between(LocalDateTime.now(), rate.getLastRequest()).toMinutes() > 0; case HOURS: return Duration.between(LocalDateTime.now(), rate.getLastRequest()).toHours() > 0; default: return false; } }
/** * Returns the uptime in the following pattern: 0 Hora(s), 1 minuto(s) e 1 segundo(s). * Tip by Ingo */ private String upTime() { Duration duration = Duration.ofMillis(ManagementFactory.getRuntimeMXBean().getUptime()); long hours = duration.toHours(); long minutes = duration.minusHours(hours).toMinutes(); long seconds = duration.minusHours(hours).minusMinutes(minutes).getSeconds(); return "<b>" + hours + "</b> Hours(s), <b>" + minutes + "</b> minute(s) and <b>" + seconds + "</b> Second(s)"; } }
private boolean canAutoLogin(Account account, RemoteSource source) { if (!settings.getGeneral().isIpAutoLogin() || source.hasPermission(PomData.ARTIFACT_ID + ".no_auto_login")) { return false; } InetAddress newIp = source.getConnection().getAddress().getAddress(); Instant now = Instant.now(); InetAddress ip = account.getIP().orElse(null); return Objects.equals(ip, newIp) && Duration.between(account.getLastLogin(), now).toHours() < 12; }
public void checkDuration(DestContextTypeMap destContextMap) { DestContextMapWrapper wrapper = new DestContextMapWrapper(destContextMap); long durationMs = CplHelper.getVirtualTrackDurationMS(contextProvider, SequenceType.VIDEO, getSequenceUUID()); Long durationS = Duration.ofMillis(durationMs).getSeconds(); if (wrapper.compareToLong(DURATION.getName(), durationS, true) < 0) { logger.warn("Duration of source in format {} supposed to be less than {} h.", destContextMap.getName(), Duration.ofMillis(wrapper.getValueAsLong(DURATION.getName())).toHours()); } }
private String getTimeString(int seconds){ Duration duration = Duration.ofSeconds(seconds); if (seconds <= 0) return "bogus time"; if (seconds < 60 ) return singularOrPlural(seconds, "second", "seconds"); if (seconds < 3600) return singularOrPlural(duration.toMinutes(), "minute", "minutes"); if (seconds < 86400) return singularOrPlural(duration.toHours(), "hour", "hours"); else return singularOrPlural(duration.toDays(), "day", "days"); }
private static String formatSpokenFutureDateWithTime(Temporal date, LocalDateTime givenDateTime) { if (givenDateTime.isBefore(LocalDateTime.now().plusHours(1))) { return NLS.get("NLS.nextHour"); } if (givenDateTime.isBefore(LocalDateTime.now().plusHours(4))) { return NLS.fmtr("NLS.inNHours") .set("hours", Duration.between(LocalDateTime.now(), givenDateTime).toHours()) .format(); } if (ChronoField.DAY_OF_MONTH.isSupportedBy(date) && !LocalDate.now().equals(LocalDate.from(date))) { return formatSpokenDate(date); } return getTimeFormat(getCurrentLang()).format(date); }
private static Interval binaryDecodeINTERVAL(int index, int len, ByteBuf buff) { Duration duration = Duration.of(buff.getLong(index), ChronoUnit.MICROS); final long hours = duration.toHours(); duration = duration.minusHours(hours); final long minutes = duration.toMinutes(); duration = duration.minusMinutes(minutes); final long seconds = NANOSECONDS.toSeconds(duration.toNanos()); duration = duration.minusSeconds(seconds); final long microseconds = NANOSECONDS.toMicros(duration.toNanos()); int days = buff.getInt(index + 8); int months = buff.getInt(index + 12); Period monthYear = Period.of(0, months, days).normalized(); return new Interval(monthYear.getYears(), monthYear.getMonths(), monthYear.getDays(), (int) hours, (int) minutes, (int) seconds, (int) microseconds); }