Example usage for org.joda.time Interval getEnd

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

Introduction

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

Prototype

public DateTime getEnd() 

Source Link

Document

Gets the end of this time interval, which is exclusive, as a DateTime.

Usage

From source file:org.kuali.kpme.tklm.time.rules.shiftdifferential.shift.ShiftCalendarInterval.java

License:Educational Community License

protected Interval incrementShift(Interval current) {
    return new Interval(current.getStart().plusDays(1), current.getEnd().plusDays(1));
}

From source file:org.kuali.kpme.tklm.time.timeblock.service.TimeBlockServiceImpl.java

License:Educational Community License

public List<TimeBlock> buildTimeBlocksSpanDates(Assignment assignment, String earnCode,
        TimesheetDocument timesheetDocument, DateTime beginDateTime, DateTime endDateTime, BigDecimal hours,
        BigDecimal amount, Boolean getClockLogCreated, Boolean getLunchDeleted, String spanningWeeks,
        String userPrincipalId) {
    DateTimeZone zone = HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback();
    DateTime beginDt = beginDateTime.withZone(zone);
    DateTime endDt = beginDt.toLocalDate().toDateTime(endDateTime.withZone(zone).toLocalTime(), zone);
    if (endDt.isBefore(beginDt))
        endDt = endDt.plusDays(1);//from w w  w . j  a  va  2 s.co  m

    List<Interval> dayInt = TKUtils.getDaySpanForCalendarEntry(timesheetDocument.getCalendarEntry());
    TimeBlock firstTimeBlock = new TimeBlock();
    List<TimeBlock> lstTimeBlocks = new ArrayList<TimeBlock>();

    DateTime endOfFirstDay = null; // KPME-2568
    long diffInMillis = 0; // KPME-2568

    for (Interval dayIn : dayInt) {
        if (dayIn.contains(beginDt)) {
            if (dayIn.contains(endDt) || dayIn.getEnd().equals(endDt)) {
                // KPME-1446 if "Include weekends" check box is checked, don't add Sat and Sun to the timeblock list
                if (StringUtils.isEmpty(spanningWeeks)
                        && (dayIn.getStart().getDayOfWeek() == DateTimeConstants.SATURDAY
                                || dayIn.getStart().getDayOfWeek() == DateTimeConstants.SUNDAY)) {
                    // Get difference in millis for the next time block - KPME-2568
                    endOfFirstDay = endDt.withZone(zone);
                    diffInMillis = endOfFirstDay.minus(beginDt.getMillis()).getMillis();
                } else {
                    firstTimeBlock = createTimeBlock(timesheetDocument, beginDateTime, endDt, assignment,
                            earnCode, hours, amount, false, getLunchDeleted, userPrincipalId);
                    lstTimeBlocks.add(firstTimeBlock);
                }
            } else {
                //TODO move this to prerule validation
                //throw validation error if this case met error
            }
        }
    }

    DateTime endTime = endDateTime.withZone(zone);
    if (firstTimeBlock.getEndDateTime() != null) { // KPME-2568
        endOfFirstDay = firstTimeBlock.getEndDateTime().withZone(zone);
        diffInMillis = endOfFirstDay.minus(beginDt.getMillis()).getMillis();
    }
    DateTime currTime = beginDt.plusDays(1);
    while (currTime.isBefore(endTime) || currTime.isEqual(endTime)) {
        // KPME-1446 if "Include weekends" check box is checked, don't add Sat and Sun to the timeblock list
        if (StringUtils.isEmpty(spanningWeeks) && (currTime.getDayOfWeek() == DateTimeConstants.SATURDAY
                || currTime.getDayOfWeek() == DateTimeConstants.SUNDAY)) {
            // do nothing
        } else {
            TimeBlock tb = createTimeBlock(timesheetDocument, currTime, currTime.plus(diffInMillis), assignment,
                    earnCode, hours, amount, false, getLunchDeleted, userPrincipalId);
            lstTimeBlocks.add(tb);
        }
        currTime = currTime.plusDays(1);
    }
    return lstTimeBlocks;
}

From source file:org.kuali.kpme.tklm.time.timeblock.service.TimeBlockServiceImpl.java

License:Educational Community License

public List<TimeBlock> buildTimeBlocks(Assignment assignment, String earnCode,
        TimesheetDocument timesheetDocument, DateTime beginDateTime, DateTime endDateTime, BigDecimal hours,
        BigDecimal amount, Boolean getClockLogCreated, Boolean getLunchDeleted, String userPrincipalId) {

    //Create 1 or many timeblocks if the span of timeblocks exceed more than one
    //day that is determined by pay period day(24 hrs + period begin date)
    Interval firstDay = null;/*from  ww w .jav a2  s.  c om*/
    List<Interval> dayIntervals = TKUtils.getDaySpanForCalendarEntry(timesheetDocument.getCalendarEntry());
    List<TimeBlock> lstTimeBlocks = new ArrayList<TimeBlock>();
    DateTime currentDateTime = beginDateTime;

    for (Interval dayInt : dayIntervals) {
        // the time period spans more than one day
        if (firstDay != null) {
            if (!dayInt.contains(endDateTime)) {
                currentDateTime = dayInt.getStart();
            } else if ((dayInt.getStartMillis() - endDateTime.getMillis()) != 0) {
                TimeBlock tb = createTimeBlock(timesheetDocument, dayInt.getStart(), endDateTime, assignment,
                        earnCode, hours, amount, getClockLogCreated, getLunchDeleted, userPrincipalId);
                lstTimeBlocks.add(tb);
                break;
            }
        }
        if (dayInt.contains(currentDateTime)) {
            firstDay = dayInt;
            // KPME-361
            // added a condition to handle the time block which ends at 12a, e.g. a 10p-12a timeblock
            // this is the same fix as TkTimeBlockAggregate
            if (dayInt.contains(endDateTime) || (endDateTime.getMillis() == dayInt.getEnd().getMillis())) {
                //create one timeblock if contained in one day interval
                TimeBlock tb = createTimeBlock(timesheetDocument, currentDateTime, endDateTime, assignment,
                        earnCode, hours, amount, getClockLogCreated, getLunchDeleted, userPrincipalId);
                tb.setBeginDateTime(currentDateTime);
                tb.setEndDateTime(endDateTime);
                lstTimeBlocks.add(tb);
                break;
            } else {
                // create a timeblock that wraps the 24 hr day
                TimeBlock tb = createTimeBlock(timesheetDocument, currentDateTime, dayInt.getEnd(), assignment,
                        earnCode, hours, amount, getClockLogCreated, getLunchDeleted, userPrincipalId);
                tb.setBeginDateTime(currentDateTime);
                tb.setEndDateTime(firstDay.getEnd());
                lstTimeBlocks.add(tb);
            }
        }
    }
    return lstTimeBlocks;
}

From source file:org.kuali.kpme.tklm.time.util.TkTimeBlockAggregate.java

License:Educational Community License

public TkTimeBlockAggregate(List<TimeBlock> timeBlocks, CalendarEntry payCalendarEntry, Calendar payCalendar,
        boolean useUserTimeZone, List<Interval> dayIntervals) {
    this.payCalendarEntry = payCalendarEntry;
    this.payCalendar = payCalendar;

    for (Interval dayInt : dayIntervals) {
        List<TimeBlock> dayTimeBlocks = new ArrayList<TimeBlock>();
        for (TimeBlock timeBlock : timeBlocks) {

            // Assumption: Timezones can only be switched at pay period end boundaries.
            // If the above assumption becomes false, the logic below will need to
            // accommodate virtual chopping of time blocks to have them fit nicely
            // in the "days" that are displayed to users.

            DateTime beginTime = useUserTimeZone ? timeBlock.getBeginTimeDisplay()
                    : timeBlock.getBeginDateTime().withZone(TKUtils.getSystemDateTimeZone());
            DateTime endTime = useUserTimeZone ? timeBlock.getEndTimeDisplay()
                    : timeBlock.getEndDateTime().withZone(TKUtils.getSystemDateTimeZone());
            if (dayInt.contains(beginTime)) {
                if (dayInt.contains(endTime) || endTime.compareTo(dayInt.getEnd()) == 0) {
                    // determine if the time block needs to be pushed forward / backward
                    if (beginTime.getHourOfDay() < dayInt.getStart().getHourOfDay()) {
                        timeBlock.setPushBackward(true);
                    }//ww w . j a  v a  2s. c o m

                    dayTimeBlocks.add(timeBlock);
                }
            }
        }
        dayTimeBlockList.add(dayTimeBlocks);
    }
}

From source file:org.kuali.kpme.tklm.time.util.TkTimeBlockAggregate.java

License:Educational Community License

public TkTimeBlockAggregate(List<TimeBlock> timeBlocks, List<LeaveBlock> leaveBlocks,
        CalendarEntry payCalendarEntry, Calendar payCalendar, boolean useUserTimeZone,
        List<Interval> dayIntervals) {
    this.payCalendarEntry = payCalendarEntry;
    this.payCalendar = payCalendar;

    for (Interval dayInt : dayIntervals) {
        List<TimeBlock> dayTimeBlocks = new ArrayList<TimeBlock>();
        for (TimeBlock timeBlock : timeBlocks) {

            // Assumption: Timezones can only be switched at pay period end boundaries.
            // If the above assumption becomes false, the logic below will need to
            // accommodate virtual chopping of time blocks to have them fit nicely
            // in the "days" that are displayed to users.

            DateTime beginTime = useUserTimeZone ? timeBlock.getBeginTimeDisplay()
                    : new DateTime(timeBlock.getBeginTimestamp(), TKUtils.getSystemDateTimeZone());
            DateTime endTime = useUserTimeZone ? timeBlock.getEndTimeDisplay()
                    : new DateTime(timeBlock.getEndTimestamp(), TKUtils.getSystemDateTimeZone());
            if (dayInt.contains(beginTime)) {
                if (dayInt.contains(endTime) || endTime.compareTo(dayInt.getEnd()) == 0) {
                    // determine if the time block needs to be pushed forward / backward
                    if (beginTime.getHourOfDay() < dayInt.getStart().getHourOfDay()) {
                        timeBlock.setPushBackward(true);
                    }//from w w  w  .ja  v a 2 s .com

                    dayTimeBlocks.add(timeBlock);
                }
            }
        }
        dayTimeBlockList.add(dayTimeBlocks);

        List<LeaveBlock> dayLeaveBlocks = new ArrayList<LeaveBlock>();
        for (LeaveBlock leaveBlock : leaveBlocks) {

            // Assumption: Timezones can only be switched at pay period end boundaries.
            // If the above assumption becomes false, the logic below will need to
            // accommodate virtual chopping of leave blocks to have them fit nicely
            // in the "days" that are displayed to users.

            DateTimeZone dateTimeZone = HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback();
            DateTime beginTime = new DateTime(leaveBlock.getLeaveDate(),
                    useUserTimeZone ? dateTimeZone : TKUtils.getSystemDateTimeZone());
            DateTime endTime = new DateTime(leaveBlock.getLeaveDate(),
                    useUserTimeZone ? dateTimeZone : TKUtils.getSystemDateTimeZone());
            if (dayInt.contains(beginTime)) {
                if (dayInt.contains(endTime) || endTime.compareTo(dayInt.getEnd()) == 0) {
                    dayLeaveBlocks.add(leaveBlock);
                }
            }
        }
        dayLeaveBlockList.add(dayLeaveBlocks);
    }
}

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();/*from w  w w  .jav  a  2 s . c o  m*/

        } 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.AvailabilityTimeLine.java

License:Open Source License

public List<Interval> getValidPeriods() {
    List<Interval> result = new ArrayList<>();
    DatePoint previous = StartOfTime.create();

    for (Interval each : invalids) {
        DatePoint invalidStart = each.start;
        if (!invalidStart.equals(StartOfTime.create()) && !invalidStart.equals(EndOfTime.create())) {
            result.add(new Interval(previous, invalidStart));
        }//w w w  . ja  v a  2 s .  c  o  m

        previous = each.getEnd();
    }

    if (!previous.equals(EndOfTime.create())) {
        result.add(new Interval(previous, EndOfTime.create()));
    }

    return result;
}

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

License:Open Source License

/**
 * Calculates if there are enough hours/*from  ww w . j a v a2 s  . c o  m*/
 */
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();/*  ww  w . j  a  va2s . c om*/
    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/*from w w w  .j a v 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));
                }
            });
}