Example usage for java.time Duration toMinutes

List of usage examples for java.time Duration toMinutes

Introduction

In this page you can find the example usage for java.time Duration toMinutes.

Prototype

public long toMinutes() 

Source Link

Document

Gets the number of minutes in this duration.

Usage

From source file:Main.java

public static void main(String[] args) {
    Duration duration = Duration.between(LocalTime.MIDNIGHT, LocalTime.NOON);
    System.out.println(duration.toMinutes());

}

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:fi.hsl.parkandride.itest.PredictionITest.java

private static void assertIsNear(DateTime expected, DateTime actual) {
    Instant i1 = Instant.ofEpochMilli(expected.getMillis());
    Instant i2 = Instant.ofEpochMilli(actual.getMillis());
    Duration d = Duration.between(i1, i2).abs();
    assertThat(d.toMinutes()).as("distance to " + expected + " in minutes")
            .isLessThanOrEqualTo(PredictionRepository.PREDICTION_RESOLUTION.getMinutes());
}

From source file:de.lgblaumeiser.ptm.analysis.analyzer.ProjectComputer.java

private String formatDuration(final Duration duration) {
    long minutes = duration.toMinutes();
    char pre = minutes < 0 ? '-' : ' ';
    minutes = Math.abs(minutes);//from w  ww. ja  va2  s  .  c om
    return String.format("%c%02d,%02d", pre, minutes / 60, minutes % 60 * 10 / 6);
}

From source file:de.lgblaumeiser.ptm.analysis.analyzer.HourComputer.java

private String formatDuration(final Duration duration) {
    long minutes = duration.toMinutes();
    char pre = minutes < 0 ? '-' : ' ';
    minutes = Math.abs(minutes);/*  w w  w  . j ava2s  . c  om*/
    return String.format("%c%02d:%02d", pre, minutes / 60, minutes % 60);
}

From source file:de.lgblaumeiser.ptm.analysis.analyzer.ProjectComputer.java

@Override
public Collection<Collection<Object>> analyze(final Collection<String> parameter) {
    Collection<Collection<Object>> result = Lists.newArrayList();
    result.add(Arrays.asList("Activity", "Booking number", "Hours", "%"));
    Duration totalMinutes = Duration.ZERO;
    Map<Activity, Duration> activityToMinutesMap = Maps.newHashMap();
    for (Booking current : getRelevantBookings(parameter)) {
        if (current.hasEndtime()) {
            Activity currentActivity = current.getActivity();
            Duration accumulatedMinutes = activityToMinutesMap.get(currentActivity);
            if (accumulatedMinutes == null) {
                accumulatedMinutes = Duration.ZERO;
            }/*from   w w  w. jav  a2s. c om*/
            Duration activityLength = current.calculateTimeSpan().getLengthInMinutes();
            totalMinutes = totalMinutes.plus(activityLength);
            accumulatedMinutes = accumulatedMinutes.plus(activityLength);
            activityToMinutesMap.put(currentActivity, accumulatedMinutes);
        }
    }
    for (Entry<Activity, Duration> currentActivity : activityToMinutesMap.entrySet()) {
        Activity activity = currentActivity.getKey();
        Duration totalMinutesId = currentActivity.getValue();
        double percentage = (double) totalMinutesId.toMinutes() / (double) totalMinutes.toMinutes();
        String percentageString = String.format("%2.1f", percentage * 100.0);
        result.add(Arrays.asList(activity.getActivityName(), activity.getBookingNumber(),
                formatDuration(totalMinutesId), percentageString));
    }
    return result;
}

From source file:de.lgblaumeiser.ptm.analysis.analyzer.HourComputer.java

private String validate(final Duration worktime, final Duration breaktime) {
    long worktimeMinutes = worktime.toMinutes();
    long breaktimeMinutes = breaktime.toMinutes();
    if (worktimeMinutes > 600) {
        return WORKTIME_COMMENT;
    }/* w  w w.  j  a  va 2s . c om*/
    if (worktimeMinutes > 540 && breaktimeMinutes < 45) { // longer than 9 hours => 45 minutes break
        return BREAKTIME_COMMENT;
    }
    if (worktimeMinutes > 360 && breaktimeMinutes < 30) { // longer than 6 hours => 30 minutes break
        return BREAKTIME_COMMENT;
    }
    return StringUtils.EMPTY;
}

From source file:org.wallride.service.PostService.java

@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void updatePostViews() {
    LocalDateTime now = LocalDateTime.now();
    Set<JobExecution> jobExecutions = jobExplorer.findRunningJobExecutions("updatePostViewsJob");
    for (JobExecution jobExecution : jobExecutions) {
        LocalDateTime startTime = LocalDateTime.ofInstant(jobExecution.getStartTime().toInstant(),
                ZoneId.systemDefault());
        Duration d = Duration.between(now, startTime);
        if (Math.abs(d.toMinutes()) == 0) {
            logger.info("Skip processing because the job is running.");
            return;
        }// w  ww . j  a va  2  s  .c  o m
    }

    JobParameters params = new JobParametersBuilder()
            .addDate("now", Date.from(now.atZone(ZoneId.systemDefault()).toInstant())).toJobParameters();
    try {
        jobLauncher.run(updatePostViewsJob, params);
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}

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   w w w. j a  v  a 2s .  co 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);
    }
}