Example usage for org.joda.time LocalDate getDayOfWeek

List of usage examples for org.joda.time LocalDate getDayOfWeek

Introduction

In this page you can find the example usage for org.joda.time LocalDate getDayOfWeek.

Prototype

public int getDayOfWeek() 

Source Link

Document

Get the day of week field value.

Usage

From source file:org.goobi.production.model.bibliography.course.Issue.java

License:Open Source License

/**
 * The function isMatch() returns whether the issue appeared on a given
 * LocalDate, taking into consideration the daysOfWeek of regular
 * appearance, the Set of exclusions and the Set of additions.
 *
 * @param date//  w  ww. j  a v a 2 s. com
 *            a LocalDate to examine
 * @return whether the issue appeared that day
 */
public boolean isMatch(LocalDate date) {
    return daysOfWeek.contains(date.getDayOfWeek()) && !exclusions.contains(date) || additions.contains(date);
}

From source file:org.isisaddons.app.kitchensink.dom.date.DateObject.java

License:Apache License

public String validateSomeJodaLocalDateWithValidation(final org.joda.time.LocalDate i) {
    return i.getDayOfWeek() == DateTimeConstants.MONDAY ? "Can't enter Monday (don't like Mondays)" : null;
}

From source file:org.kuali.kpme.tklm.leave.accrual.service.AccrualServiceImpl.java

License:Educational Community License

@Override
public boolean isDateAtEarnInterval(LocalDate aDate, String earnInterval) {
    boolean atEarnInterval = false;
    if (HrConstants.ACCRUAL_EARN_INTERVAL_MAP.containsKey(earnInterval)) {
        if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.DAILY)) {
            atEarnInterval = true;//from  w  ww . j a  v a2 s . co  m
        } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.WEEKLY)) {
            // figure out if the day is a Saturday
            if (aDate.getDayOfWeek() == DateTimeConstants.SATURDAY) {
                atEarnInterval = true;
            }
        } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.SEMI_MONTHLY)) {
            // either the 15th or the last day of the month
            if (aDate.getDayOfMonth() == 15 || aDate.getDayOfMonth() == aDate.dayOfMonth().getMaximumValue()) {
                atEarnInterval = true;
            }
        } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.MONTHLY)) {
            // the last day of the month
            if (aDate.getDayOfMonth() == aDate.dayOfMonth().getMaximumValue()) {
                atEarnInterval = true;
            }
        } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.YEARLY)) {
            // the last day of the year
            if (aDate.getDayOfYear() == aDate.dayOfYear().getMaximumValue()) {
                atEarnInterval = true;
            }
        } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.NO_ACCRUAL)) {
            // no calculation
        }
    }
    return atEarnInterval;
}

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

License:Open Source License

private Days getDayFrom(LocalDate date) {
    return Days.values()[date.getDayOfWeek() - 1];
}

From source file:org.mifos.application.meeting.business.MeetingBO.java

License:Open Source License

public LocalDate startDateForMeetingInterval(LocalDate date) {
    LocalDate startOfMeetingInterval = date;
    if (isWeekly()) {
        int weekDay = WeekDay.getJodaDayOfWeekThatMatchesMifosWeekDay(
                getFiscalCalendarRules().getStartOfWeekWeekDay().getValue());
        while (startOfMeetingInterval.getDayOfWeek() != weekDay) {
            startOfMeetingInterval = startOfMeetingInterval.minusDays(1);
        }/*w w w.  j a v  a2  s.  c om*/
    } else if (isMonthly()) {
        int dayOfMonth = date.getDayOfMonth();
        startOfMeetingInterval = startOfMeetingInterval.minusDays(dayOfMonth - 1);
    } else {
        // for days we return the same day
        startOfMeetingInterval = date;
    }
    return startOfMeetingInterval;
}

From source file:org.mifosplatform.portfolio.loanaccount.loanschedule.service.LoanScheduleAssembler.java

License:Mozilla Public License

private CalendarInstance createInterestRecalculationCalendarInstance(final LocalDate calendarStartDate,
        final RecalculationFrequencyType recalculationFrequencyType, final Integer frequency) {
    final Integer repeatsOnDay = calendarStartDate.getDayOfWeek();

    CalendarFrequencyType calendarFrequencyType = CalendarFrequencyType.INVALID;
    switch (recalculationFrequencyType) {
    case DAILY:/*from   w w  w .  java2s.co m*/
        calendarFrequencyType = CalendarFrequencyType.DAILY;
        break;
    case MONTHLY:
        calendarFrequencyType = CalendarFrequencyType.MONTHLY;
        break;
    case WEEKLY:
        calendarFrequencyType = CalendarFrequencyType.WEEKLY;
        break;
    default:
        break;
    }

    final String title = "loan_recalculation_detail";
    final Calendar calendar = Calendar.createRepeatingCalendar(title, calendarStartDate,
            CalendarType.COLLECTION.getValue(), calendarFrequencyType, frequency, repeatsOnDay);
    return CalendarInstance.from(calendar, null, CalendarEntityType.LOAN_RECALCULATION_REST_DETAIL.getValue());
}

From source file:org.mifosplatform.portfolio.savings.domain.SavingsAccountCharge.java

License:Mozilla Public License

private SavingsAccountCharge(final SavingsAccount savingsAccount, final Charge chargeDefinition,
        final BigDecimal amount, final ChargeTimeType chargeTime, final ChargeCalculationType chargeCalculation,
        final LocalDate dueDate, final boolean status, MonthDay feeOnMonthDay, final Integer feeInterval) {

    this.savingsAccount = savingsAccount;
    this.charge = chargeDefinition;
    this.penaltyCharge = chargeDefinition.isPenalty();
    this.chargeTime = (chargeTime == null) ? chargeDefinition.getChargeTime() : chargeTime.getValue();

    if (isOnSpecifiedDueDate()) {
        if (dueDate == null) {
            final String defaultUserMessage = "Savings Account charge is missing due date.";
            throw new SavingsAccountChargeWithoutMandatoryFieldException("savingsaccount.charge",
                    dueAsOfDateParamName, defaultUserMessage, chargeDefinition.getId(),
                    chargeDefinition.getName());
        }/*from www .ja v  a 2 s.  c om*/

    }

    if (isAnnualFee() || isMonthlyFee()) {
        feeOnMonthDay = (feeOnMonthDay == null) ? chargeDefinition.getFeeOnMonthDay() : feeOnMonthDay;
        if (feeOnMonthDay == null) {
            final String defaultUserMessage = "Savings Account charge is missing due date.";
            throw new SavingsAccountChargeWithoutMandatoryFieldException("savingsaccount.charge",
                    dueAsOfDateParamName, defaultUserMessage, chargeDefinition.getId(),
                    chargeDefinition.getName());
        }

        this.feeOnMonth = feeOnMonthDay.getMonthOfYear();
        this.feeOnDay = feeOnMonthDay.getDayOfMonth();

    } else if (isWeeklyFee()) {
        if (dueDate == null) {
            final String defaultUserMessage = "Savings Account charge is missing due date.";
            throw new SavingsAccountChargeWithoutMandatoryFieldException("savingsaccount.charge",
                    dueAsOfDateParamName, defaultUserMessage, chargeDefinition.getId(),
                    chargeDefinition.getName());
        }
        /**
         * For Weekly fee feeOnDay is ISO standard day of the week.
         * Monday=1, Tuesday=2
         */
        this.feeOnDay = dueDate.getDayOfWeek();
    } else {
        this.feeOnDay = null;
        this.feeOnMonth = null;
        this.feeInterval = null;
    }

    if (isMonthlyFee() || isWeeklyFee()) {
        this.feeInterval = (feeInterval == null) ? chargeDefinition.feeInterval() : feeInterval;
    }

    this.dueDate = (dueDate == null) ? null : dueDate.toDate();

    this.chargeCalculation = chargeDefinition.getChargeCalculation();
    if (chargeCalculation != null) {
        this.chargeCalculation = chargeCalculation.getValue();
    }

    BigDecimal chargeAmount = chargeDefinition.getAmount();
    if (amount != null) {
        chargeAmount = amount;
    }

    final BigDecimal transactionAmount = new BigDecimal(0);

    populateDerivedFields(transactionAmount, chargeAmount);

    if (this.isWithdrawalFee()) {
        this.amountOutstanding = BigDecimal.ZERO;
    }

    this.paid = determineIfFullyPaid();
    this.status = status;
}

From source file:org.mifosplatform.portfolio.savings.service.DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java

License:Mozilla Public License

private CalendarInstance getCalendarInstance(final JsonCommand command, RecurringDepositAccount account) {
    CalendarInstance calendarInstance = null;
    final boolean isCalendarInherited = command
            .booleanPrimitiveValueOfParameterNamed(isCalendarInheritedParamName);

    if (isCalendarInherited) {
        Set<Group> groups = account.getClient().getGroups();
        Long groupId = null;/*from   www . j  ava2 s.  c o  m*/
        if (groups.isEmpty()) {
            final String defaultUserMessage = "Client does not belong to group/center. Cannot follow group/center meeting frequency.";
            throw new GeneralPlatformDomainRuleException(
                    "error.msg.recurring.deposit.account.cannot.create.not.belongs.to.any.groups.to.follow.meeting.frequency",
                    defaultUserMessage, account.clientId());
        } else if (groups.size() > 1) {
            final String defaultUserMessage = "Client belongs to more than one group. Cannot support recurring deposit.";
            throw new GeneralPlatformDomainRuleException(
                    "error.msg.recurring.deposit.account.cannot.create.belongs.to.multiple.groups",
                    defaultUserMessage, account.clientId());
        } else {
            Group group = groups.iterator().next();
            Group parent = group.getParent();
            Integer entityType = CalendarEntityType.GROUPS.getValue();
            if (parent != null) {
                groupId = parent.getId();
                entityType = CalendarEntityType.CENTERS.getValue();
            } else {
                groupId = group.getId();
            }
            CalendarInstance parentCalendarInstance = this.calendarInstanceRepository
                    .findByEntityIdAndEntityTypeIdAndCalendarTypeId(groupId, entityType,
                            CalendarType.COLLECTION.getValue());
            calendarInstance = CalendarInstance.from(parentCalendarInstance.getCalendar(), account.getId(),
                    CalendarEntityType.SAVINGS.getValue());
        }
    } else {
        LocalDate calendarStartDate = account.depositStartDate();
        final Integer frequencyType = command
                .integerValueSansLocaleOfParameterNamed(recurringFrequencyTypeParamName);
        final PeriodFrequencyType periodFrequencyType = PeriodFrequencyType.fromInt(frequencyType);
        final Integer frequency = command.integerValueSansLocaleOfParameterNamed(recurringFrequencyParamName);

        final Integer repeatsOnDay = calendarStartDate.getDayOfWeek();
        final String title = "recurring_savings_" + account.getId();
        final Calendar calendar = Calendar.createRepeatingCalendar(title, calendarStartDate,
                CalendarType.COLLECTION.getValue(), CalendarFrequencyType.from(periodFrequencyType), frequency,
                repeatsOnDay);
        calendarInstance = CalendarInstance.from(calendar, account.getId(),
                CalendarEntityType.SAVINGS.getValue());
    }
    if (calendarInstance == null) {
        final String defaultUserMessage = "No valid recurring details available for recurring depost account creation.";
        throw new GeneralPlatformDomainRuleException(
                "error.msg.recurring.deposit.account.cannot.create.no.valid.recurring.details.available",
                defaultUserMessage, account.clientId());
    }
    return calendarInstance;
}

From source file:org.onebusaway.admin.service.bundle.task.FixedRouteDataValidationTask.java

License:Apache License

private LocalDate getFirstDay(int dayOfWeek) {
    LocalDate today = LocalDate.now();
    int old = today.getDayOfWeek();
    if (dayOfWeek < old) {
        dayOfWeek += 7;// www.  j a va  2  s  . c om
    }
    return today.plusDays(dayOfWeek - old);
}

From source file:org.onebusaway.webapp.actions.admin.bundles.CompareBundlesAction.java

License:Apache License

private LocalDate getFirstDay(int dayOfWeek, LocalDate startDate) {
    int old = startDate.getDayOfWeek();
    if (dayOfWeek < old) {
        dayOfWeek += 7;/*w w  w.  ja v a2 s  . c o  m*/
    }
    return startDate.plusDays(dayOfWeek - old);
}