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:com.stagecents.pay.domain.ElementType.java

License:Open Source License

void updateTimecard(Timecard timecard, Activity activity, Interval timeWorked) {
    LocalDate dateWorked = timeWorked.getStart().toLocalDate();

    SummaryHours sh = timecard.getSummaryHours(dateWorked);
    if (sh == null) {
        int seq = timecard.getSummaryHoursSequence(dateWorked);
        sh = new SummaryHours(timecard, seq, dateWorked);
    }/* www .  j a v  a2  s  .  c om*/
    sh.updateHours(activity, this, timeWorked);
}

From source file:com.stagecents.pay.domain.Overtime.java

License:Open Source License

@Override
public void processHours(Interval interval, Activity activity, Timecard timecard, Position position) {
    DateTime start = interval.getStart();
    DateTime end = interval.getEnd();/*from w w  w  . j  a v  a 2 s .  c  o m*/

    // 1. Test start time against normal start time.
    DateTime regStart = start;
    if (position.getNormalStart() != null) {
        DateTime normalStart = start.toLocalDate().toDateTime(position.getNormalStart());
        regStart = regStart.isBefore(normalStart) ? normalStart : regStart;
    }

    // Update the time card with any premium time prior to the position's
    // normal start
    if (start.isBefore(regStart)) {
        updateTimecard(timecard, activity, new Interval(start, regStart));
    }

    // 2. Test end time against minimum call.
    MinimumCallValue mc = getMinimumCall(new Interval(start, end));
    if (mc != null) {
        long minCall = (long) mc.getDefaultValue() * 1000 * 60 * 60;
        DateTime minCallEnd = end.plus(minCall);
        end = end.isBefore(minCallEnd) ? minCallEnd : end;
    }

    // Test end time against normal end time.
    DateTime regEnd = end;
    if (position.getNormalEnd() != null) {
        DateTime normalEnd = end.toLocalDate().toDateTime(position.getNormalEnd());
        regEnd = normalEnd.isBefore(regEnd) ? normalEnd : regEnd;
    }

    // Test end time against maximum time for position.
    if (position.getMaximumHours() > 0) {
        float priorHrs = getPriorHours(timecard, regStart.toLocalDate());
        long availMillis = (long) (position.getMaximumHours() - priorHrs) * 1000 * 60 * 60;
        DateTime availEnd = regStart.plus(availMillis);
        regEnd = availEnd.isBefore(regEnd) ? availEnd : regEnd;
    }

    // Update the timecard with any premium time after the position's normal
    // end
    if (regEnd.isBefore(end)) {
        updateTimecard(timecard, activity, new Interval(regEnd, end));
    }
}

From source file:com.stagecents.pay.domain.PayCycle.java

License:Open Source License

public LocalDate getCycleStart(Interval arg) {
    LocalDate result = null;/*w  w w.j a  v a2s.  c  om*/
    if (frequency.equals(Frequency.W)) {
        result = getWeeklyCycleStart(arg).toLocalDate();

    } else if (frequency.equals(Frequency.F)) {
        // TODO Need to compute biweekly start date

    } else if (frequency.equals(Frequency.SM)) {
        result = (arg.getStart().getDayOfMonth() <= 15)
                ? arg.getStart().dayOfMonth().withMinimumValue().toLocalDate()
                : arg.getStart().withDayOfMonth(15).toLocalDate();

    } else if (frequency.equals(Frequency.CM)) {
        result = arg.getStart().withDayOfMonth(1).toLocalDate();

    } else if (frequency.equals(Frequency.Q)) {
        int adjStartMonth = getQuarterStartMonth(arg.getStart().getMonthOfYear());
        result = arg.getStart().withMonthOfYear(adjStartMonth).withDayOfMonth(1).toLocalDate();
    }
    return result;
}

From source file:com.stagecents.pay.domain.PayCycle.java

License:Open Source License

private DateTime getWeeklyCycleStart(Interval arg) {
    int argStartDOW = arg.getStart().getDayOfWeek();
    int cycleStartDOW = (periodEndDay.getIsoValue() == 7) ? 1 : periodEndDay.getIsoValue() + 1;

    DateTime cycleStart = null;/*www .  j  ava  2 s. c om*/
    if (argStartDOW < cycleStartDOW) {
        cycleStart = arg.getStart().minusDays(argStartDOW - cycleStartDOW).withTimeAtStartOfDay();
    } else {
        cycleStart = arg.getStart().minusDays(argStartDOW - cycleStartDOW + 7).withTimeAtStartOfDay();
    }
    return cycleStart;
}

From source file:com.stagecents.pay.domain.PayCycle.java

License:Open Source License

/**
 * Returns the number of semimonthly pay cycles in the given time interval.
 * //from   ww w  .j  a v a  2s  .  co  m
 * @param arg The time period to analyze.
 * @return The number of semimonthly pay cycles in the given time interval.
 */
private int getSemiMonthlyCycles(Interval arg) {
    int startPer = arg.getStart().getDayOfMonth() <= 15 ? 1 : 2;
    int endPer = arg.getEnd().getDayOfMonth() <= 15 ? 1 : 2;
    DateTime adjStart = (arg.getStart().getDayOfMonth() <= 15) ? arg.getStart().dayOfMonth().withMinimumValue()
            : arg.getStart().withDayOfMonth(15);
    DateTime adjEnd = (arg.getEnd().getDayOfMonth() <= 15) ? arg.getEnd().dayOfMonth().withMinimumValue()
            : arg.getEnd().dayOfMonth().withMaximumValue();

    return (Months.monthsBetween(adjStart, adjEnd).getMonths() * 2) + ((startPer == endPer) ? 1 : 2);
}

From source file:com.stagecents.pay.domain.PayCycle.java

License:Open Source License

/**
 * Returns the number of monthly pay cycles in the given time interval.
 * //w w w .  j a  v  a  2  s  . c  o  m
 * @param arg The time interval to analyze.
 * @return The number of monthly pay cycles in the given time interval.
 */
private int getMonthlyCycles(Interval arg) {
    DateTime adjStart = arg.getStart().withDayOfMonth(1);
    DateTime adjEnd = (arg.getEnd().getDayOfMonth() < 15) ? arg.getEnd().withDayOfMonth(1)
            : arg.getEnd().dayOfMonth().withMaximumValue();

    return Months.monthsBetween(adjStart, adjEnd).getMonths() + 1;
}

From source file:com.stagecents.pay.domain.PayCycle.java

License:Open Source License

/**
 * Returns the number of calendar quarters in the given time interval.
 * //from   w w w .  j  a  v a2s  .  c om
 * @param arg The time interval to analyze.
 * @return The number of calendar quarters in the given time interval.
 */
private int getQuarterlyCycles(Interval arg) {
    int adjStartMonth = getQuarterStartMonth(arg.getStart().getMonthOfYear());
    int adjEndMonth = getQuarterEndMonth(arg.getEnd().getMonthOfYear());
    DateTime adjStart = arg.getStart().withMonthOfYear(adjStartMonth).withDayOfMonth(1);
    DateTime adjEnd = arg.getEnd().withMonthOfYear(adjEndMonth).dayOfMonth().withMaximumValue();

    return (int) Math.ceil((Months.monthsBetween(adjStart, adjEnd).getMonths() + 1) / 3d);
}

From source file:com.stagecents.pay.domain.PayCycle.java

License:Open Source License

/**
 * Returns the number of calendar years in the given time interval.
 * // ww w  .  ja v  a  2 s.  c om
 * @param arg The time interval to analyze.
 * @return The number of calendar years.
 */
private int getAnnualCycles(Interval arg) {
    return arg.getEnd().getYear() - arg.getStart().getYear() + 1;
}

From source file:com.stagecents.pay.domain.RegularWages.java

License:Open Source License

protected void doProcessHours(Interval interval, Activity activity, Timecard timecard, Position position) {
    DateTime start = interval.getStart();
    DateTime end = interval.getEnd();/*  ww  w  .j  a  v a 2s  .co m*/

    // Test start time against normal start time.
    if (position.getNormalStart() != null) {
        DateTime normalStart = start.toLocalDate().toDateTime(position.getNormalStart());
        start = start.isBefore(normalStart) ? normalStart : start;
    }

    // Test end time against minimum call.
    MinimumCallValue mc = getMinimumCall(activity.duration());
    if (mc != null) {
        long minCall = (long) mc.getDefaultValue() * 1000 * 60 * 60;
        DateTime minCallEnd = end.plus(minCall);
        end = end.isBefore(minCallEnd) ? minCallEnd : end;
    }

    // Test end time against normal end time.
    if (position.getNormalEnd() != null) {
        DateTime normalEnd = end.toLocalDate().toDateTime(position.getNormalEnd());
        end = end.isAfter(normalEnd) ? normalEnd : end;
    }

    // Test end time against maximum time for position.
    if (position.getMaximumHours() > 0) {
        float priorHours = getPriorHours(timecard, start.toLocalDate());
        long availMillis = (long) (position.getMaximumHours() - priorHours) * 1000 * 60 * 60;
        DateTime availEnd = start.plus(availMillis);
        end = availEnd.isBefore(end) ? availEnd : end;
    }

    updateTimecard(timecard, activity, new Interval(start, end));
}

From source file:com.stagecents.pay.domain.RegularWages.java

License:Open Source License

private RateValue getRate(Interval interval) {
    Iterator<InputValue> iter = inputValues.iterator();
    while (iter.hasNext()) {
        InputValue iv = iter.next();/* w ww . j  av  a2 s.c  om*/
        if (iv instanceof RateValue) {
            RateValue rv = (RateValue) iv;
            if (rv.getEffectiveDateRange() == null || isEffective(interval.getStart())) {
                return rv;
            }
        }
    }
    return null;
}