List of usage examples for java.time Duration toHours
public long toHours()
From source file:Main.java
public static void main(String[] args) { Duration duration = Duration.between(LocalTime.MIDNIGHT, LocalTime.NOON); System.out.println(duration.toHours()); }
From source file:com.querydsl.webhooks.GithubReviewWindow.java
@VisibleForTesting protected static String makeHumanReadable(Duration duration) { StringBuilder output = new StringBuilder(); duration = truncateAndAppend(duration, duration.toDays(), ChronoUnit.DAYS, "day", output); duration = truncateAndAppend(duration, duration.toHours(), ChronoUnit.HOURS, "hour", output); duration = truncateAndAppend(duration, duration.toMinutes(), ChronoUnit.MINUTES, "minute", output); duration = truncateAndAppend(duration, duration.getSeconds(), ChronoUnit.SECONDS, "second", output); return output.toString().trim(); }
From source file:org.ng200.openolympus.controller.api.ContestTimerController.java
@RequestMapping("/api/contestTimeRemaining/{contest}") public @ResponseBody Map<String, String> getTimeRemaining(@PathVariable("contest") final Contest contest, final Principal principal) { Assertions.resourceExists(contest);//from w ww . j a va2 s. co m Instant end = contest.getStartTime().toInstant(); final boolean isInProcess = contest.getStartTime().before(java.util.Date.from(Instant.now())); if (isInProcess) { if (this.contestSecurityService.isSuperuser(principal)) { end = this.contestService.getContestEndIncludingAllTimeExtensions(contest); } else if (principal != null) { final User user = this.userRepository.findByUsername(principal.getName()); if (user != null) { end = end.plusMillis(contest.getDuration()) .plusMillis(this.contestService.getTimeExtensions(contest, user)); } } } if (principal != null) { this.contestService.getTimeExtensions(contest, this.userRepository.findByUsername(principal.getName())); } final Instant cur = Instant.now(); if (end.isBefore(cur)) { return new HashMap<String, String>() { /** * */ private static final long serialVersionUID = 5419629757758058933L; { this.put("timer", "00:00:00"); this.put("status", "ended"); } }; } final Duration duration = Duration.between(cur, end); final DecimalFormat format = new DecimalFormat("00"); final long hours = duration.toHours(); final long minutes = duration.minusHours(hours).toMinutes(); final long seconds = duration.minusHours(hours).minusMinutes(minutes).getSeconds(); return new HashMap<String, String>() { /** * */ private static final long serialVersionUID = -4698243010184691932L; { this.put("timer", format.format(hours) + ":" + format.format(minutes) + ":" + format.format(seconds)); this.put("status", isInProcess ? "inProgress" : "notStartedYet"); } }; }
From source file:net.di2e.ecdr.describe.generator.DescribeGeneratorImpl.java
protected void setRecordRate(MetricsType metrics, Map<String, TemporalCoverageHolder> timeMap) { TemporalCoverageHolder tc = timeMap.containsKey("modified") ? (TemporalCoverageHolder) timeMap.get("modified") : (timeMap.containsKey("effective") ? (TemporalCoverageHolder) timeMap.get("effective") : (TemporalCoverageHolder) timeMap.get("created")); try {/*from www . j a v a2 s. c o m*/ if (tc != null) { Date startDate = tc.getStartDate(); if (startDate != null) { long totalHits = metrics.getCount(); LocalDateTime start = LocalDateTime.ofInstant(startDate.toInstant(), ZoneId.systemDefault()); Duration duration = Duration.between(start, LocalDateTime.now()); RecordRateType rate = new RecordRateType(); metrics.setRecordRate(rate); long dur = totalHits / duration.toHours(); if (dur < 15L) { dur = totalHits / duration.toDays(); if (dur < 4L) { dur = totalHits * 30L / duration.toDays(); if (dur < 10L) { dur = totalHits * 365L / duration.toDays(); rate.setFrequency("Yearly"); } else { rate.setFrequency("Monthly"); } } else { rate.setFrequency("Daily"); } } else if (totalHits > 1000L) { dur = duration.toMinutes(); if (totalHits > 1000L) { dur = duration.toMillis() / 1000L; rate.setFrequency("Second"); } else { rate.setFrequency("Minute"); } } else { rate.setFrequency("Hourly"); } rate.setValue((int) dur); } } } catch (Exception e) { LOGGER.warn("Could not set record rate: {}", e.getMessage(), e); } }
From source file:org.kitodo.production.services.data.ProcessService.java
/** * Calculate and return duration/age of given process as a String. * * @param process ProcessDTO object for which duration/age is calculated * @return process age of given process/*from w w w . jav a 2 s .c o m*/ */ public static String getProcessDuration(ProcessDTO process) { String creationDateTimeString = process.getCreationDate(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); LocalDateTime createLocalDate = LocalDateTime.parse(creationDateTimeString, formatter); Duration duration = Duration.between(createLocalDate, LocalDateTime.now()); return String.format("%sd; %sh", duration.toDays(), duration.toHours() - TimeUnit.DAYS.toHours(duration.toDays())); }