Example usage for org.joda.time Duration plus

List of usage examples for org.joda.time Duration plus

Introduction

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

Prototype

public Duration plus(ReadableDuration amount) 

Source Link

Document

Returns a new duration with this length plus that specified.

Usage

From source file:julian.lylly.model.Task.java

public Duration getTimeSpentInInterval(Interval focus) {
    if (focus == null) {
        throw new IllegalArgumentException("focus == nul");
    }/* w ww. j av a  2s.  c  om*/

    Duration timespent = Duration.ZERO;

    for (Interval i : intervals) {
        Duration ov = computeOverlap(i, focus);
        timespent = timespent.plus(ov);
    }
    if (isActive()) {
        Interval activeInterval = new Interval(starttime, Instant.now());
        Duration overlapDuration = computeOverlap(activeInterval, focus);
        timespent = timespent.plus(overlapDuration);
    }

    return timespent;
}

From source file:julian.lylly.model.TaskOrganizerImpl.java

@Override
public Duration getInvestedTime(LocalDate start, LocalDate end, Tag tag) {
    Duration sum = Duration.ZERO;
    for (Task task : toDo) {
        // Check for null, because some tasks may not have a tag
        if (task.getTag() != null) {
            if (task.getTag().equals(tag)) {
                sum = sum.plus(task.getTimeSpentInInterval(start, end));
            }/*  ww w. j  a va  2 s  . c  o m*/
        }
    }
    return sum;
}

From source file:kr.debop4j.timeperiod.calendars.CalendarDateDiff.java

License:Apache License

/**
 *  ? ~  ? ?? ? Working Time? ./* w  ww.ja va 2  s .c  om*/
 *
 * @param fromTime  ?
 * @param toTime    ?
 * @return  ? ~  ? ?? Working Hours
 */
public Duration difference(DateTime fromTime, DateTime toTime) {
    if (CalendarDateDiff.log.isTraceEnabled())
        CalendarDateDiff.log.trace("fromTime[{}] ~ toTime[{}]? Working Time? .", fromTime,
                toTime);

    if (Objects.equals(fromTime, toTime))
        return Zero;

    boolean filterIsEmpty = this.getWeekDays().size() == 0 && this.getWorkingHours().size() == 0
            && this.getWorkingDayHours().size() == 0;

    if (filterIsEmpty) {
        return new DateDiff(fromTime, toTime, getCalendar()).getDifference();
    }

    TimeRange differenceRange = new TimeRange(fromTime, toTime);
    CalendarPeriodCollector collector = new CalendarPeriodCollector(this.collectorFilter,
            new TimeRange(startTimeOfDay(differenceRange.getStart()),
                    startTimeOfDay(differenceRange.getEnd()).plusDays(1)),
            SeekDirection.Forward, getCalendar());
    // Gap? .
    TimeGapCalculator<TimeRange> gapCalculator = new TimeGapCalculator<>(getCalendar());
    ITimePeriodCollection gaps = gapCalculator.getGaps(collector.getPeriods(), differenceRange);
    Duration difference = Zero;
    for (ITimePeriod gap : gaps) {
        difference.plus(gap.getDuration());
    }

    if (CalendarDateDiff.log.isTraceEnabled())
        CalendarDateDiff.log.trace(
                "fromTime[{}] ~ toTime[{}]? Working Time? . differece=[{}]", fromTime,
                toTime, difference);

    return (fromTime.compareTo(toTime) <= 0) ? difference : negate(difference);
}

From source file:net.sf.jacclog.service.importer.commands.internal.ImportStatsShellCommand.java

License:Apache License

private void renderEntries(final LogFileImporterStatistic statistic) {
    if (statistic.getEntries() != null && !statistic.getEntries().isEmpty()) {
        final int size = (statistic.getEntries().get(0).getFile() != null)
                ? statistic.getEntries().get(0).getFile().getFile().getPath().length() + 8
                : 32;/*from  w w  w.  j a v a2s.co  m*/
        final String format = "%-" + size + "s%10s%18s";
        final StringBuilder builder = new StringBuilder();
        builder.append('\n');
        final Formatter formatter = new Formatter(builder);
        formatter.format(format, "Path", "Count", "Elapsed time");
        builder.append('\n');

        String path;
        Period p;
        int totalCount = 0;
        Duration totalElapsedTime = new Duration(0);
        for (final Entry entry : statistic.getEntries()) {
            path = entry.getFile().getFile().getPath();
            p = entry.getElapsedTime();
            totalElapsedTime = totalElapsedTime.plus(p.toStandardDuration());
            totalCount += entry.getCount();
            formatter.format(format, path, entry.getCount(), p.toString(FORMATTER));
            builder.append('\n');
        }

        builder.append('\n');
        builder.append("Total imported entries: " + totalCount);
        builder.append('\n');
        builder.append("Total processing time: " + totalElapsedTime.toPeriod().toString(FORMATTER));
        builder.append('\n');

        System.out.println(builder);
    } else {
        System.out.println("No files have been recently imported.");
    }
}

From source file:net.sourceforge.fenixedu.domain.ExecutionCourse.java

License:Open Source License

public Duration getTotalShiftsDuration() {
    Duration totalDuration = Duration.ZERO;
    for (Shift shift : getAssociatedShifts()) {
        totalDuration = totalDuration.plus(shift.getTotalDuration());
    }/*from  w  ww .  ja v  a  2 s . c o m*/
    return totalDuration;
}

From source file:net.sourceforge.fenixedu.domain.Shift.java

License:Open Source License

public Duration getTotalDuration() {
    Duration duration = Duration.ZERO;
    Collection<Lesson> lessons = getAssociatedLessonsSet();
    for (Lesson lesson : lessons) {
        duration = duration.plus(lesson.getTotalDuration());
    }//from  www.  j  ava2  s. co  m
    return duration;
}

From source file:net.sourceforge.fenixedu.domain.Teacher.java

License:Open Source License

public Duration getLecturedDurationOnExecutionCourse(ExecutionCourse executionCourse) {
    Duration duration = Duration.ZERO;
    Professorship professorship = getProfessorshipByExecutionCourse(executionCourse);
    TeacherService teacherService = getTeacherServiceByExecutionPeriod(executionCourse.getExecutionPeriod());
    if (teacherService != null) {
        List<DegreeTeachingService> teachingServices = teacherService
                .getDegreeTeachingServiceByProfessorship(professorship);
        for (DegreeTeachingService teachingService : teachingServices) {
            duration = duration.plus(new Duration(new Double((teachingService.getPercentage() / 100)
                    * teachingService.getShift().getCourseLoadWeeklyAverage().doubleValue() * 3600 * 1000)
                            .longValue()));
        }/*from   ww  w  .  ja v  a2 s . c  o m*/
    }
    return duration;
}

From source file:org.openehr.rm.datatypes.quantity.datetime.DvDuration.java

License:LGPL

/**
 * Sum of this quantity and another whose formal type must be the difference
 * type of this quantity./* w w  w . j  av  a 2  s  . com*/
 * 
 * @param q
 * @return production of addition
 * @throws ClassCastException
 */
@Override
public DvQuantified<DvDuration> add(DvQuantified q) {
    final DvDuration d = (DvDuration) q;

    DateTime dt = new DateTime(0);
    Duration duration = period.toDurationFrom(dt);
    Duration result = duration.plus(d.period.toDurationFrom(dt));
    Period p = result.toPeriodFrom(dt);

    return new DvDuration(d.getOtherReferenceRanges(), d.getNormalRange(), d.getNormalStatus(), d.getAccuracy(),
            d.isAccuracyPercent(), d.getMagnitudeStatus(), p);
}

From source file:org.openmastery.publisher.core.timeline.BandTimelineSegment.java

License:Open Source License

public Duration getDuration() {
    Duration duration = TimeBandModel.sumDuration(ideaFlowBands);
    return duration.plus(TimeBandModel.sumDuration(timeBandGroups));
}

From source file:org.openmastery.publisher.core.timeline.TimeBandModel.java

License:Open Source License

public static Duration sumDuration(List<? extends TimeBandModel> ideaFlowBands) {
    Duration duration = Duration.ZERO;
    for (TimeBandModel ideaFlowBand : ideaFlowBands) {
        Duration bandDuration = ideaFlowBand.getDuration();
        if (bandDuration.getMillis() < 0) {
            throw new BandDurationIsNegativeException(ideaFlowBand);
        }//ww  w . j  a  v  a2s  . c  om
        duration = duration.plus(bandDuration);
    }
    return duration;
}