Example usage for java.time Duration plus

List of usage examples for java.time Duration plus

Introduction

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

Prototype

public Duration plus(Duration duration) 

Source Link

Document

Returns a copy of this duration with the specified duration added.

Usage

From source file:Main.java

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

}

From source file:Main.java

public static void main(String[] args) {
    Duration d1 = Duration.ofSeconds(55);
    Duration d2 = Duration.ofSeconds(-17);

    Instant i1 = Instant.now();

    Instant i4 = i1.plus(d1);/*from  www .  j a v  a2 s .c o  m*/
    Instant i5 = i1.minus(d2);

    Duration d3 = d1.plus(d2);
    System.out.println(d3);
}

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

private Duration calculateWorktime(Collection<Booking> bookings) {
    Duration minutes = Duration.ZERO;
    for (Booking current : bookings) {
        minutes = minutes.plus(current.calculateTimeSpan().getLengthInMinutes());
    }//from  www .j  a  v  a 2  s.co m
    return minutes;
}

From source file:com.drunkendev.io.recurse.tests.RecursionTest.java

/**
 * Used to perform a timed average of a repeated set of runs.
 *
 * @param   count//w w  w .  j  a va 2s . c o m
 *          Amount of times to run {@code r}.
 * @param   r
 *          {@link Runnable} object to perform tests against.
 */
public void averageTest(int count, Runnable r) {
    Duration total = Duration.ZERO;
    for (int i = 0; i < count; i++) {
        total = total.plus(time(() -> r.run()));
    }
    System.out.format("%nAverage duration: %s%n%n", total.dividedBy(count));
}

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.  ja v  a2s .  c  o  m*/
            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

@Override
public Collection<Collection<Object>> analyze(final Collection<String> parameter) {
    YearMonth requestedMonth = YearMonth.now();
    if (parameter.size() > 0) {
        requestedMonth = YearMonth.parse(Iterables.get(parameter, 0));
    }/*from w  ww .  j ava 2  s .c om*/
    Collection<Collection<Object>> result = Lists.newArrayList();
    result.add(Arrays.asList("Work Day", "Starttime", "Endtime", "Presence", "Worktime", "Breaktime",
            "Overtime", "Comment"));
    Duration overtime = Duration.ZERO;
    LocalDate currentday = requestedMonth.atDay(1);
    while (!currentday.isAfter(requestedMonth.atEndOfMonth())) {
        Collection<Booking> currentBookings = getBookingsForDay(currentday);
        if (hasCompleteBookings(currentBookings)) {
            String day = currentday.format(DateTimeFormatter.ISO_LOCAL_DATE);
            LocalTime starttime = Iterables.getFirst(currentBookings, null).getStarttime();
            LocalTime endtime = Iterables.getLast(currentBookings).getEndtime();
            Duration presence = calculatePresence(starttime, endtime);
            Duration worktime = calculateWorktime(currentBookings);
            Duration breaktime = calculateBreaktime(presence, worktime);
            Duration currentOvertime = calculateOvertime(worktime, currentday);
            overtime = overtime.plus(currentOvertime);
            result.add(Arrays.asList(day, starttime.format(DateTimeFormatter.ofPattern("HH:mm")),
                    endtime.format(DateTimeFormatter.ofPattern("HH:mm")), formatDuration(presence),
                    formatDuration(worktime), formatDuration(breaktime), formatDuration(overtime),
                    validate(worktime, breaktime)));
        }
        currentday = currentday.plusDays(1);
    }
    return result;
}