Example usage for java.sql Date before

List of usage examples for java.sql Date before

Introduction

In this page you can find the example usage for java.sql Date before.

Prototype

public boolean before(Date when) 

Source Link

Document

Tests if this date is before the specified date.

Usage

From source file:org.kuali.coeus.common.budget.impl.print.BudgetBaseStream.java

/**
 * This method set reportTypeMap from reportTypeVOList by grouping based on
 * reportTypeKey and get sum of salaryRequested, calculatedCost, first
 * startDate, last endDate/*from  w  w w. j a v  a  2s .  c  o m*/
 * 
 * @param tempReportTypeVOList
 * @param reportTypeMap
 */
protected void setReportTypeMapFromReportTypeVOList(List<ReportTypeVO> tempReportTypeVOList,
        Map<String, ReportType> reportTypeMap) {
    for (ReportTypeVO reportTypeVO : tempReportTypeVOList) {
        String reportTypeKey = getKeyForRateBase(reportTypeVO);
        if (reportTypeMap.containsKey(reportTypeKey)) {
            continue;
        }
        Date startDate = reportTypeVO.getStartDate();
        Date endDate = reportTypeVO.getEndDate();
        ScaleTwoDecimal calculatedCost = ScaleTwoDecimal.ZERO;
        ScaleTwoDecimal salaryRequested = ScaleTwoDecimal.ZERO;
        for (ReportTypeVO tempReportTypeVO : tempReportTypeVOList) {
            String reportTypeTempKey = getKeyForRateBase(tempReportTypeVO);
            if (reportTypeTempKey.equals(reportTypeKey)) {
                salaryRequested = salaryRequested.add(tempReportTypeVO.getSalaryRequested());
                calculatedCost = calculatedCost.add(tempReportTypeVO.getCalculatedCost());
                if (startDate.after(tempReportTypeVO.getStartDate())) {
                    startDate = tempReportTypeVO.getStartDate();
                }
                if (endDate.before(tempReportTypeVO.getEndDate())) {
                    endDate = tempReportTypeVO.getEndDate();
                }
            }
        }
        ReportType reportType = getReportTypeForRateAndBase(startDate, endDate, calculatedCost, salaryRequested,
                reportTypeVO);
        reportTypeMap.put(reportTypeKey, reportType);
    }
}

From source file:org.kuali.coeus.common.budget.impl.print.BudgetBaseStream.java

/**
 * This method set reportTypeMap for BudgetOHRateAndBase by grouping based
 * on budgetOHRateBaseKey and get sum of salaryRequested, calculatedCost,
 * first startDate, last endDate/*from  ww w . j a  v  a  2s  .  co  m*/
 * 
 * @param tempReportTypeVOList
 * @param reportTypeMap
 */
protected void setReportTypeMapForBudgetOHRateAndBase(List<ReportTypeVO> tempReportTypeVOList,
        Map<String, ReportType> reportTypeMap) {
    for (ReportTypeVO reportTypeVO : tempReportTypeVOList) {
        String budgetOHRateBaseKey = getKeyForBudgetOHRateBase(reportTypeVO);
        if (reportTypeMap.containsKey(budgetOHRateBaseKey)) {
            continue;
        }
        Date startDate = reportTypeVO.getStartDate();
        Date endDate = reportTypeVO.getEndDate();
        ScaleTwoDecimal calculatedCost = ScaleTwoDecimal.ZERO;
        ScaleTwoDecimal salaryRequested = ScaleTwoDecimal.ZERO;
        for (ReportTypeVO tempReportTypeVO : tempReportTypeVOList) {
            String budgetOHRateBaseTempKey = getKeyForBudgetOHRateBase(tempReportTypeVO);
            if (budgetOHRateBaseTempKey.equals(budgetOHRateBaseKey)) {
                salaryRequested = salaryRequested
                        .add(tempReportTypeVO.getSalaryRequested() == null ? ScaleTwoDecimal.ZERO
                                : tempReportTypeVO.getSalaryRequested());
                calculatedCost = calculatedCost.add(tempReportTypeVO.getCalculatedCost());
                if (startDate.after(tempReportTypeVO.getStartDate())) {
                    startDate = tempReportTypeVO.getStartDate();
                }
                if (endDate.before(tempReportTypeVO.getEndDate())) {
                    endDate = tempReportTypeVO.getEndDate();
                }
            }
        }
        ReportType reportType = getReportTypeForBudgetOHRateAndBase(startDate, endDate, calculatedCost,
                salaryRequested, reportTypeVO);
        reportTypeMap.put(budgetOHRateBaseKey, reportType);
    }
}

From source file:org.kuali.coeus.common.budget.impl.summary.BudgetSummaryServiceImpl.java

/**
 * /* w  ww .  jav a 2  s . c  o m*/
 * This method is to be shared by adjusting dates for budgetperiod.lineitem and lineitem.personnellineitem
 * refer to jira-1376 for rules
 */
protected List<Date> getNewStartEndDates(Date parentStartDate, Date oldStartDate, Date parentEndDate,
        Date oldEndDate, List<Date> startEndDates) {
    Date startDate = startEndDates.get(0);
    Date endDate = startEndDates.get(1);
    Date newStartDate = startDate;
    Date newEndDate = endDate;
    if (startDate.compareTo(oldStartDate) == 0 && endDate.compareTo(oldEndDate) == 0) {
        // if initiall, both are matching, then keep matching.
        newStartDate = parentStartDate;
        newEndDate = parentEndDate;
    } else {
        // duration has priority over child start date relative to parent start date
        if (parentStartDate.compareTo(oldStartDate) != 0) {
            // keep the gap between child start date and parent start date
            newStartDate = add(newStartDate,
                    getDateTimeService().dateDiff(oldStartDate, parentStartDate, false));
            if (newStartDate.after(parentEndDate)) {
                newStartDate = parentStartDate;
            } else {
                if (newStartDate.after(parentStartDate)) {
                    // keep the duration, but the item start date relative to period start date is not maintained.
                    int parentDuration = getDateTimeService().dateDiff(parentStartDate, parentEndDate, false);
                    int duration = getDateTimeService().dateDiff(startDate, endDate, false);
                    int daysTOEndDate = getDateTimeService().dateDiff(newStartDate, parentEndDate, false);
                    if (daysTOEndDate < duration) {
                        if (parentDuration > duration) {
                            newEndDate = parentEndDate;
                            newStartDate = add(newEndDate, duration * (-1));
                        } else {
                            // can't keep duration because parent duration is smaller than child initial duration
                            newStartDate = parentStartDate;
                        }
                    }
                }
            }
            newEndDate = add(newStartDate, getDateTimeService().dateDiff(startDate, endDate, false));
            if (newEndDate.after(parentEndDate)) {
                newEndDate = parentEndDate;
            }
        } else {
            // end date changed
            if (parentEndDate.compareTo(oldStartDate) != 0 && parentEndDate.before(endDate)) {
                if (parentEndDate.after(startDate) && parentEndDate.before(endDate)) {
                    newEndDate = parentEndDate;
                    // try to keep duration
                    newStartDate = add(newEndDate, getDateTimeService().dateDiff(endDate, startDate, false));
                    if (newStartDate.before(parentStartDate)) {
                        newStartDate = parentStartDate;
                    }
                } else {
                    if (parentEndDate.before(startDate)) {
                        newStartDate = parentStartDate;
                        newEndDate = add(newStartDate,
                                getDateTimeService().dateDiff(startDate, endDate, false));
                        if (newEndDate.after(parentEndDate)) {
                            newEndDate = parentEndDate;
                        }
                    }
                }
            }
        }
    }
    startEndDates.clear();
    startEndDates.add(0, newStartDate);
    startEndDates.add(1, newEndDate);
    return startEndDates;
}

From source file:org.kuali.coeus.common.budget.impl.summary.BudgetSummaryServiceImpl.java

@Override
public List<Date> getNewStartEndDates(List<Date> startEndDates, int gap, int duration, Date prevDate,
        boolean leapDayInPeriod, boolean leapDayInGap) {
    // duration is < (enddate - start date)
    Date startDate = startEndDates.get(0);
    Date endDate = startEndDates.get(1);
    Date newStartDate = startDate;
    Date newEndDate = endDate;
    boolean endDateAdjusted = false;
    if (gap == 0) {
        newEndDate = add(startDate, duration);
        ;/*from  ww w. j a  v  a  2  s.co  m*/
    } else {
        // keep the gap between child start date and parent start date
        newStartDate = add(startDate, gap);
        newEndDate = add(newStartDate, duration);
        ;
        if (newStartDate.after(endDate)) {
            newStartDate = startDate;
            newEndDate = add(startDate, duration);
        } else if (newEndDate.after(endDate)) {
            endDateAdjusted = true;
            newEndDate = endDate;
            newStartDate = add(endDate, duration * (-1));
        }
    }
    boolean isLeapDayInNewGap = isLeapDaysInPeriod(startDate, newStartDate);

    startEndDates.clear();
    if (leapDayInGap && !endDateAdjusted) {
        if (newStartDate.after(startDate)) {
            // shift non-leap year date
            newStartDate = add(newStartDate, -1);
            newEndDate = add(newEndDate, -1);
        }
    } else if (isLeapDayInNewGap) {
        if (newEndDate.before(endDate)) {
            // shift leap year date
            newStartDate = add(newStartDate, 1);
            newEndDate = add(newEndDate, 1);
        }

    }
    boolean isLeapDayInNewPeriod = isLeapDaysInPeriod(newStartDate, newEndDate);

    if (leapDayInPeriod && !isLeapDayInNewPeriod) {
        newEndDate = add(newEndDate, -1);
    } else if (!leapDayInPeriod && isLeapDayInNewPeriod) {
        if (endDate.after(newEndDate)) {
            newEndDate = add(newEndDate, 1);
        } else if (startDate.before(newStartDate)) {
            newStartDate = add(newStartDate, 1);

        }

    }

    startEndDates.add(0, newStartDate);
    startEndDates.add(1, newEndDate);
    return startEndDates;
}

From source file:org.kuali.coeus.common.budget.impl.summary.BudgetSummaryServiceImpl.java

@Override
public boolean isLeapDaysInPeriod(Date sDate, Date eDate) {
    Date leapDate;//from   w ww  .  ja  va 2  s .c  o m
    int sYear = getYear(sDate);
    int eYear = getYear(eDate);
    if (isLeapYear(sDate)) {
        Calendar c1 = Calendar.getInstance();
        c1.clear();
        c1.set(sYear, 1, 29);
        leapDate = new java.sql.Date(c1.getTime().getTime());
        // start date is before 2/29 & enddate >= 2/29
        if (sDate.before(leapDate)) {
            if (eDate.compareTo(leapDate) >= 0) {
                return true;
            }
        } else if (sDate.equals(leapDate)) {
            return true;
        }
    } else if (isLeapYear(eDate)) {
        Calendar c1 = Calendar.getInstance();
        c1.set(eYear, 1, 29);
        leapDate = new java.sql.Date(c1.getTime().getTime());
        if (eDate.compareTo(leapDate) >= 0) {
            return true;
        }
    } else {
        sYear++;
        while (eYear > sYear) {
            if (isLeapYear(sYear)) {
                return true;
            }
            sYear++;
        }
    }
    return false;
}

From source file:org.kuali.coeus.common.committee.impl.bo.CommitteeBase.java

private boolean isChairPerson(CommitteeMembershipBase committeeMembership) {

    boolean isChairRoleFound = false;
    Date currentDate = DateUtils.clearTimeFields(new Date(System.currentTimeMillis()));

    for (CommitteeMembershipRole committeeMembershipRole : committeeMembership.getMembershipRoles()) {
        if (committeeMembershipRole.getMembershipRoleCode().equals(CHAIR_MEMBERSHIP_ROLE_CODE)
                && committeeMembershipRole.getStartDate() != null
                && committeeMembershipRole.getEndDate() != null
                && !currentDate.before(committeeMembershipRole.getStartDate())
                && !currentDate.after(committeeMembershipRole.getEndDate())) {
            isChairRoleFound = true;// w  ww.j ava 2s  . c o  m
            break;
        }
    }
    return isChairRoleFound;
}

From source file:org.kuali.coeus.common.committee.impl.bo.CommitteeMembershipBase.java

/**
 * /*w  w  w  .j  a v  a 2 s . co  m*/
 * This method determines if the current committee member is active for the given date
 * @param date
 * @return true if member is active, false otherwise
 */
public boolean isActive(Date date) {
    boolean isActive = false;
    for (CommitteeMembershipRole role : membershipRoles) {
        if (role.getStartDate() != null && role.getEndDate() != null && !date.before(role.getStartDate())
                && !date.after(role.getEndDate())) {
            if (role.getMembershipRoleCode().equals(CommitteeMembershipRole.INACTIVE_ROLE)) {
                isActive = false;
                break;
            } else {
                isActive = true;
            }
        }
    }
    return isActive;
}

From source file:org.kuali.coeus.common.committee.impl.meeting.MeetingServiceImplBase.java

private boolean isActiveForScheduledDate(Date scheduledDate, Date startDate, Date endDate) {
    return startDate.before(scheduledDate) && endDate.after(scheduledDate);
}

From source file:org.kuali.coeus.common.committee.impl.rules.CommitteeDocumentRuleBase.java

/**
 * Check if the date is outside the committee membership term.
 * If any of the date are null the method returns false.
 * //w w  w .java2s . co m
 * @param committeeMembership - the committeeMembership whose term we are comparing against
 * @param date - the date to be checked
 * @return <code>true</code> if the date is outside the committee membership term, <code>false</code> otherwise
 */
private boolean hasDateOutsideCommitteeMembershipTerm(CommitteeMembershipBase committeeMembership, Date date) {
    boolean isOutside = false;
    if ((committeeMembership.getTermStartDate() != null) && (committeeMembership.getTermEndDate() != null)
            && (date != null)) {
        if (date.before(committeeMembership.getTermStartDate())
                || date.after(committeeMembership.getTermEndDate())) {
            isOutside = true;
        }
    }
    return isOutside;
}

From source file:org.kuali.coeus.common.committee.impl.rules.CommitteeDocumentRuleBase.java

/**
 * Verify that a date is within a period
 * /*w  ww .j  a v a  2s . c  o  m*/
 * @param date - the date that needs to be within the period
 * @param periodStart - the date on which the period begins
 * @param periodEnd - the date on which the period ends
 * @return <code>true</code> if date is within the period, <code>false</code> otherwise
 */
private boolean isWithinPeriod(Date date, Date periodStart, Date periodEnd) {
    return !(date.before(periodStart) || date.after(periodEnd));
}