Examples of PartialDay


Examples of org.libreplan.business.workingday.IntraDayDate.PartialDay

        assertThat(generated.size(), equalTo(2));
    }

    @Test
    public void aPartialDayCanLimitAWorkingDayDuration() {
        PartialDay day = new PartialDay(IntraDayDate.create(today,
                halfHour), IntraDayDate.create(today, oneHour));
        assertThat(day.limitWorkingDay(hours(10)), equalTo(minutes(30)));
        assertThat(day.limitWorkingDay(minutes(40)), equalTo(minutes(10)));
        PartialDay completeDay = new PartialDay(IntraDayDate.startOfDay(today),
                IntraDayDate.startOfDay(tomorrow));
        assertThat(completeDay.limitWorkingDay(hours(10)), equalTo(hours(10)));
        PartialDay startsInTheMiddle = new PartialDay(IntraDayDate.create(
                today, EffortDuration.hours(3)),
                IntraDayDate.startOfDay(tomorrow));
        assertThat(startsInTheMiddle.limitWorkingDay(hours(10)),
                equalTo(hours(7)));
        assertThat(startsInTheMiddle.limitWorkingDay(hours(3)), equalTo(zero()));
        assertThat(startsInTheMiddle.limitWorkingDay(hours(2)), equalTo(zero()));
        PartialDay startAndEndInSameDay = new PartialDay(IntraDayDate.create(
                today, EffortDuration.hours(3)), IntraDayDate.create(today,
                EffortDuration.hours(6)));
        assertThat(startAndEndInSameDay.limitWorkingDay(hours(4)),
                equalTo(hours(1)));
        assertThat(startAndEndInSameDay.limitWorkingDay(hours(5)),
                equalTo(hours(2)));
        assertThat(startAndEndInSameDay.limitWorkingDay(hours(6)),
                equalTo(hours(3)));
        assertThat(startAndEndInSameDay.limitWorkingDay(hours(10)),
                equalTo(hours(3)));
    }
View Full Code Here

Examples of org.libreplan.business.workingday.IntraDayDate.PartialDay

                return toPoints((Iterable<PartialDay>) param);
            }

            private List<IntraDayDate> toPoints(Iterable<PartialDay> param) {
                List<IntraDayDate> result = new ArrayList<IntraDayDate>();
                PartialDay last = null;
                for (PartialDay each : param) {
                    result.add(each.getStart());
                    last = each;
                }
                if (last != null) {
                    result.add(last.getEnd());
                }
                return result;
            }

            @Override
View Full Code Here

Examples of org.libreplan.business.workingday.IntraDayDate.PartialDay

        expect(taskCalendar.getCapacityOn(isA(PartialDay.class))).andAnswer(
                new IAnswer<EffortDuration>() {
                    @Override
                    public EffortDuration answer() throws Throwable {
                        Object[] args = getCurrentArguments();
                        PartialDay day = (PartialDay) args[0];
                        return day.getDate().equals(start.plusDays(1)) ? hours(0)
                                : hours(8);
                    }
                }).anyTimes();
        replay(taskCalendar);
View Full Code Here

Examples of org.libreplan.business.workingday.IntraDayDate.PartialDay

        expect(this.calendar.getCapacityOn(isA(PartialDay.class)))
                .andAnswer(new IAnswer<EffortDuration>() {

                    @Override
                    public EffortDuration answer() throws Throwable {
                        PartialDay day = (PartialDay) EasyMock
                                .getCurrentArguments()[0];
                        LocalDate date = day.getDate();
                        if (answersForDates.containsKey(date)) {
                            return day.limitWorkingDay(answersForDates
                                    .get(date).getStandardEffort());
                        }
                        return day.limitWorkingDay(defaultAnswer
                                .getStandardEffort());
                    }
                }).anyTimes();

        expect(this.calendar.getCapacityWithOvertime(isA(LocalDate.class)))
                .andAnswer(new IAnswer<Capacity>() {

                    @Override
                    public Capacity answer() throws Throwable {
                        LocalDate date = (LocalDate) EasyMock
                                .getCurrentArguments()[0];
                        if (answersForDates.containsKey(date)) {
                            return answersForDates.get(date);
                        }
                        return defaultAnswer;
                    }
                }).anyTimes();
        final IAnswer<EffortDuration> effortAnswer = new IAnswer<EffortDuration>() {

            @Override
            public EffortDuration answer() throws Throwable {
                PartialDay day = (PartialDay) EasyMock
                        .getCurrentArguments()[0];
                ResourcesPerDay resourcesPerDay = (ResourcesPerDay) EasyMock
                        .getCurrentArguments()[1];

                LocalDate date = day.getDate();
                Capacity capacity = answersForDates.containsKey(date) ? answersForDates
                        .get(date) : defaultAnswer;

                EffortDuration oneResourcePerDayWorkingDuration = day
                        .limitWorkingDay(capacity.getStandardEffort());
                EffortDuration amountRequestedDuration = resourcesPerDay
                        .asDurationGivenWorkingDayOf(oneResourcePerDayWorkingDuration);
                return capacity.limitDuration(amountRequestedDuration);
            }
View Full Code Here

Examples of org.libreplan.business.workingday.IntraDayDate.PartialDay

        expect(result.getCapacityOn(isA(PartialDay.class)))
                .andAnswer(new IAnswer<EffortDuration>() {

                    @Override
                    public EffortDuration answer() throws Throwable {
                        PartialDay day = (PartialDay) getCurrentArguments()[0];
                        if (availability.isValid(day.getDate())) {
                            return day.limitWorkingDay(workingDay);
                        } else {
                            return zero();
                        }
                    }
                }).anyTimes();
        expect(
                result.asDurationOn(isA(PartialDay.class),
                        isA(ResourcesPerDay.class))).andAnswer(
                new IAnswer<EffortDuration>() {

                    @Override
                    public EffortDuration answer() throws Throwable {
                        PartialDay day = (PartialDay) getCurrentArguments()[0];
                        ResourcesPerDay resourcesPerDay = (ResourcesPerDay) getCurrentArguments()[1];
                        if (availability.isValid(day.getDate())) {
                            return day.limitWorkingDay(resourcesPerDay
                                    .asDurationGivenWorkingDayOf(workingDay));
                        } else {
                            return zero();
                        }
                    }
View Full Code Here

Examples of org.libreplan.business.workingday.IntraDayDate.PartialDay

        LocalDate date = endTime.getDate();
        EffortDuration totalIntended = hours(resourceAllocation
                .getIntendedTotalHours());

        // Generate last day assignment
        PartialDay firstDay = new PartialDay(IntraDayDate.startOfDay(date),
                IntraDayDate.create(date, hours(endTime.getHour())));
        EffortDuration effortCanAllocate = min(totalIntended,
                calendar.asDurationOn(firstDay, ONE_RESOURCE_PER_DAY));
        if (effortCanAllocate.compareTo(zero()) > 0) {
            DayAssignment dayAssignment = createDayAssignment(
View Full Code Here

Examples of org.libreplan.business.workingday.IntraDayDate.PartialDay

        }

        Iterator<PartialDay> daysUntilEnd = realStart.toIntraDayDate()
                .daysUntil(endDate.toIntraDayDate()).iterator();
        while (daysUntilEnd.hasNext()) {
            PartialDay each = daysUntilEnd.next();
            int hoursAtDay = calendar.getCapacityOn(each).roundToHours();
            int hours = Math.min(hoursAtDay, total);
            total -= hours;

            // Don't add hours when total and hours are zero (it'd be like
            // adding an extra 0 hour day when total is completed)
            if (total != 0 || hours != 0) {
                result.add(hours);
            }

            if (total == 0
                    && DateAndHour.from(each.getDate())
                            .compareTo(allocationEnd) >= 0) {
                break;
            }
        }
        return result;
View Full Code Here

Examples of org.libreplan.business.workingday.IntraDayDate.PartialDay

                    PartialDay day, EffortDuration limit,
                    ResourcesPerDay resourcesPerDay) {
                EffortDuration toDistribute = getResourceAllocation()
                        .calculateTotalToDistribute(day, getGoal());
                EffortDuration effortLimited = min(limit, toDistribute);
                PartialDay distributeOn = day;
                if (effortLimited.equals(limit)) {
                    IntraDayDate start = day.getStart();
                    distributeOn = new PartialDay(start, start.increaseBy(
                            resourcesPerDay, effortLimited));
                }
                return effortDistributor.distributeForDay(distributeOn,
                        effortLimited);
            }
View Full Code Here

Examples of org.libreplan.business.workingday.IntraDayDate.PartialDay

        return EffortDuration.sum(assignments,
                new IEffortFrom<DayAssignment>() {

                    @Override
                    public EffortDuration from(DayAssignment value) {
                        PartialDay partial = getPartialDay(value,
                                startInclusive, endExclusive);
                        return partial.limitWorkingDay(value.getDuration());
                    }

                    private PartialDay getPartialDay(DayAssignment assignment,
                            IntraDayDate startInclusive,
                            IntraDayDate endExclusive) {

                        LocalDate assignmentDay = assignment.getDay();
                        LocalDate startDate = startInclusive.getDate();
                        LocalDate endDate = endExclusive.getDate();

                        PartialDay result = PartialDay.wholeDay(assignment
                                .getDay());
                        if (assignmentDay.equals(startDate)) {
                            result = new PartialDay(startInclusive, result
                                    .getEnd());
                        }
                        if (assignmentDay.equals(endDate)) {
                            result = new PartialDay(result.getStart(),
                                    endExclusive);
                        }
                        return adjustPartialDayToAllocationStart(result);
                    }

                    // if the start of the allocation is in the middle of a day,
                    // its work also starts later; so the PartialDay must be
                    // moved to earlier so it doesn't limit the duration more
                    // that it should
                    private PartialDay adjustPartialDayToAllocationStart(
                            PartialDay day) {
                        PartialDay result = day;
                        if (allocationStart.areSameDay(day.getDate())) {
                            EffortDuration substractingAtStart = day.getStart()
                                    .getEffortDuration();
                            EffortDuration newSubstractionAtStart = substractingAtStart
                                    .minus(EffortDuration
                                            .min(substractingAtStart,
                                                    allocationStart
                                                            .getEffortDuration()));
                            IntraDayDate newStart = IntraDayDate.create(
                                    day.getDate(), newSubstractionAtStart);
                            result = new PartialDay(newStart, day.getEnd());
                        }
                        return result;
                    }
                });
    }
View Full Code Here

Examples of org.libreplan.business.workingday.IntraDayDate.PartialDay

        EffortDuration biggestLastAssignment = zero();
        IntraDayDate current = dateFromWhichToAllocate;
        IAssignmentsCreator assignmentsCreator = resourcesPerDayModification
                .createAssignmentsCreator();
        while (effortRemaining.compareTo(zero()) > 0) {
            PartialDay day = calculateDay(current);
            Pair<EffortDuration, EffortDuration> pair = assignForDay(
                    resourcesPerDayModification, assignmentsCreator, day,
                    effortRemaining);
            taken = pair.getFirst();
            biggestLastAssignment = pair.getSecond();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.