Example usage for org.joda.time Interval getStart

List of usage examples for org.joda.time Interval getStart

Introduction

In this page you can find the example usage for org.joda.time Interval getStart.

Prototype

public DateTime getStart() 

Source Link

Document

Gets the start of this time interval, which is inclusive, as a DateTime.

Usage

From source file:org.libreplan.business.calendars.entities.AvailabilityTimeLine.java

License:Open Source License

public AvailabilityTimeLine or(AvailabilityTimeLine another) {
    List<Interval> intersections = doIntersections(this, another);
    AvailabilityTimeLine result = AvailabilityTimeLine.allValid();

    for (Interval each : intersections) {
        boolean fromStartOfTime = each.getStart().equals(StartOfTime.create());
        boolean untilEndOfTime = each.getEnd().equals(EndOfTime.create());

        if (fromStartOfTime && untilEndOfTime) {
            result.allInvalid();// www  .ja v  a 2  s.com

        } else if (fromStartOfTime) {
            result.invalidUntil(FixedPoint.tryExtract(each.getEnd()));

        } else if (untilEndOfTime) {
            result.invalidFrom(FixedPoint.tryExtract(each.getStart()));

        } else {
            result.invalidAt(FixedPoint.tryExtract(each.getStart()), FixedPoint.tryExtract(each.getEnd()));
        }
    }
    result.setVetoer(or(this.vetoer, another.vetoer));

    return result;
}

From source file:org.libreplan.business.calendars.entities.ThereAreHoursOnWorkHoursCalculator.java

License:Open Source License

/**
 * Calculates if there are enough hours//from   www . ja  v a  2 s  .c  om
 */
public static CapacityResult thereIsAvailableCapacityFor(ICalendar calendar, AvailabilityTimeLine availability,
        ResourcesPerDay resourcesPerDay, EffortDuration effortToAllocate) {
    if (effortToAllocate.isZero()) {
        return new CapacityAvailable();
    }
    if (resourcesPerDay.isZero()) {
        return new ResourcesPerDayIsZero();
    }
    AvailabilityTimeLine realAvailability = calendar.getAvailability().and(availability);
    List<Interval> validPeriods = realAvailability.getValidPeriods();
    if (validPeriods.isEmpty()) {
        return new ThereAreNoValidPeriods(calendar, availability);
    }

    Interval last = getLast(validPeriods);
    Interval first = validPeriods.get(0);
    final boolean isOpenEnded = last.getEnd().equals(EndOfTime.create())
            || first.getStart().equals(StartOfTime.create());
    if (isOpenEnded) {
        return new CapacityAvailable();
    }
    return thereIsCapacityOn(calendar, effortToAllocate, resourcesPerDay, validPeriods);

}

From source file:org.libreplan.business.calendars.entities.ThereAreHoursOnWorkHoursCalculator.java

License:Open Source License

private static CapacityResult thereIsCapacityOn(ICalendar calendar, EffortDuration effortToAllocate,
        ResourcesPerDay resourcesPerDay, List<Interval> validPeriods) {
    EffortDuration sum = zero();//from  ww w.  j  av  a2  s  .  co m
    for (Interval each : validPeriods) {
        FixedPoint start = (FixedPoint) each.getStart();
        FixedPoint end = (FixedPoint) each.getEnd();
        EffortDuration pending = effortToAllocate.minus(sum);
        sum = sum.plus(sumDurationUntil(calendar, pending, resourcesPerDay, start.getDate(), end.getDate()));
        if (sum.compareTo(effortToAllocate) >= 0) {
            return new CapacityAvailable();
        }
    }
    return new ValidPeriodsDontHaveCapacity(validPeriods, sum, effortToAllocate);
}

From source file:org.libreplan.business.planner.entities.SpecificResourceAllocation.java

License:Open Source License

@Override
public EffortDuration getAssignedEffort(Criterion criterion, final IntraDayDate startInclusive,
        final IntraDayDate endExclusive) {

    return EffortDuration.sum(
            getIntervalsRelatedWith(criterion, startInclusive.getDate(), endExclusive.asExclusiveEnd()),
            new IEffortFrom<Interval>() {
                @Override/*  www  .jav a  2  s.  c  o  m*/
                public EffortDuration from(Interval each) {
                    FixedPoint intervalStart = (FixedPoint) each.getStart();
                    FixedPoint intervalEnd = (FixedPoint) each.getEnd();

                    return getAssignedDuration(IntraDayDate.convert(intervalStart.getDate(), startInclusive),
                            IntraDayDate.convert(intervalEnd.getDate(), endExclusive));
                }
            });
}

From source file:org.libreplan.business.planner.limiting.entities.Gap.java

License:Open Source License

private static Gap createGap(Resource resource, Interval interval, DateAndHour originalGapStartTime,
        DateAndHour originalGapEndTime) {

    DateAndHour start = convert(originalGapStartTime, interval.getStart());
    DateAndHour end = convert(originalGapEndTime, interval.getEnd());
    return Gap.create(resource, start, end);
}

From source file:org.libreplan.business.resources.entities.CriterionSatisfaction.java

License:Open Source License

private CriterionSatisfaction(Criterion criterion, Resource resource, Interval interval) {
    this(interval.getStart(), criterion, resource);
    if (interval.getEnd() != null) {
        this.finish(interval.getEnd());
    }/*from  www .  jav  a2 s  .c o m*/
}

From source file:org.libreplan.business.resources.entities.Resource.java

License:Open Source License

public void modifySatisfaction(CriterionSatisfaction original, Interval interval) {
    /* Create a temporal criterion satisfaction. */
    CriterionType type = original.getCriterion().getType();
    CriterionSatisfaction temporal = createNewSatisfaction(interval, original.getCriterion());
    temporal.setResource(this);

    boolean canAdd = false;
    if (contains(original)) {
        try {//  w  w w  .ja  v  a2s. c o  m
            removeCriterionSatisfaction(original);
            canAdd = canAddSatisfaction(type, temporal);
            if (canAdd) {
                //update original
                original.setStartDate(interval.getStart());
                original.finish(interval.getEnd());
            }
            original.validate();
            criterionSatisfactions.add(original);
            if (!canAdd) {
                throw new IllegalStateException("This interval " + original.getCriterion().getName()
                        + " not is valid because exists overlap with other criterion satisfaction");
            }
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException(original.getCriterion().getName() + " : " + e.getMessage());
        }
    } else {
        throw new IllegalStateException("The criterion satisfaction " + original.getCriterion().getName()
                + " not is activated for this resource");
    }
}

From source file:org.n52.io.img.ChartRenderer.java

License:Open Source License

protected Date getStartTime(String timespan) {
    Interval interval = Interval.parse(timespan);
    return interval.getStart().toDate();
}

From source file:org.n52.janmayen.Times.java

License:Apache License

public static String encodeInterval(Interval interval) {
    return String.format("%s/%s", encodeDateTime(interval.getStart()), encodeDateTime(interval.getEnd()));
}

From source file:org.n52.series.db.dao.DbQuery.java

License:Open Source License

public Criteria addTimespanTo(Criteria criteria) {
    if (parameters.getTimespan() != null) {
        Interval interval = parameters.getTimespan().toInterval();
        Date start = interval.getStart().toDate();
        Date end = interval.getEnd().toDate();
        criteria.add(Restrictions.or( // check overlap
                between(COLUMN_TIMESTART, start, end), between(COLUMN_TIMEEND, start, end)));
    }// w w w  . j  a  v a2  s .co m
    return criteria;
}