Example usage for org.joda.time LocalDate now

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

Introduction

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

Prototype

public static LocalDate now() 

Source Link

Document

Obtains a LocalDate set to the current system millisecond time using ISOChronology in the default time zone.

Usage

From source file:com.einzig.ipst2.parse.EmailParseTask.java

License:Open Source License

@Override
protected Void doInBackground(Void... voids) {
    Logger.d("Parsing email");
    LocalDate now = LocalDate.now();
    for (int i = 0; i < messages.length; i++) {
        PortalSubmission p = parser.getPortal(messages[i]);
        addPortal(p);// ww  w . j ava 2 s .c om
        publishProgress(i, messages.length);
        if (isCancelled()) {
            try {
                now = new LocalDate(messages[i].getReceivedDate());
            } catch (MessagingException e) {
                Logger.e(e.toString());
            }
            break;
        }
    }
    onEmailParse(now);
    bundle.cleanup();
    return null;
}

From source file:com.einzig.ipst2.portal.PortalResponded.java

License:Open Source License

@Override
public int getDaysSinceResponse() {
    return Days.daysBetween(dateResponded, LocalDate.now()).getDays();
}

From source file:com.einzig.ipst2.portal.PortalSubmission.java

License:Open Source License

public int getDaysSinceResponse() {
    return Days.daysBetween(dateSubmitted, LocalDate.now()).getDays();
}

From source file:com.garethahealy.brms.services.HelloWorldService.java

License:Apache License

public Person doSomething(Person person) {
    KieSession session = kieSessionFactory.getStatefulSession();

    try {/*from w ww .  j  a va 2s  . c  o  m*/
        session.insert(LocalDate.now());
        session.insert(person);
        session.fireAllRules();
    } finally {
        kieSessionFactory.disposeOf(session);
    }

    return person;
}

From source file:com.google.api.ads.adwords.awalerting.util.DateRange.java

License:Open Source License

/**
 * Parse DateRange in ReportDefinitionDateRangeType enum format.
 *//*from w w  w. j ava 2s.com*/
private static DateRange parseEnumFormat(String dateRange) {
    ReportDefinitionDateRangeType dateRangeType;
    try {
        dateRangeType = ReportDefinitionDateRangeType.valueOf(dateRange);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Unknown DateRange type: " + dateRange);
    }

    LocalDate today = LocalDate.now();
    LocalDate startDate;
    LocalDate endDate;
    switch (dateRangeType) {
    case TODAY:
        startDate = endDate = today;
        break;
    case YESTERDAY:
        startDate = endDate = today.minusDays(1);
        break;
    case LAST_7_DAYS:
        startDate = today.minusDays(7);
        endDate = today.minusDays(1);
        break;
    case LAST_WEEK:
        LocalDate.Property lastWeekProp = today.minusWeeks(1).dayOfWeek();
        startDate = lastWeekProp.withMinimumValue();
        endDate = lastWeekProp.withMaximumValue();
        break;
    case THIS_MONTH:
        LocalDate.Property thisMonthProp = today.dayOfMonth();
        startDate = thisMonthProp.withMinimumValue();
        endDate = thisMonthProp.withMaximumValue();
        break;
    case LAST_MONTH:
        LocalDate.Property lastMonthProp = today.minusMonths(1).dayOfMonth();
        startDate = lastMonthProp.withMinimumValue();
        endDate = lastMonthProp.withMaximumValue();
        break;
    case LAST_14_DAYS:
        startDate = today.minusDays(14);
        endDate = today.minusDays(1);
        break;
    case LAST_30_DAYS:
        startDate = today.minusDays(30);
        endDate = today.minusDays(1);
        break;
    case THIS_WEEK_SUN_TODAY:
        // Joda-Time uses the ISO standard Monday to Sunday week.
        startDate = today.minusWeeks(1).dayOfWeek().withMaximumValue();
        endDate = today;
        break;
    case THIS_WEEK_MON_TODAY:
        startDate = today.dayOfWeek().withMinimumValue();
        endDate = today;
        break;
    case LAST_WEEK_SUN_SAT:
        startDate = today.minusWeeks(2).dayOfWeek().withMaximumValue();
        endDate = today.minusWeeks(1).dayOfWeek().withMaximumValue().minusDays(1);
        break;
    // Don't support the following enums
    case LAST_BUSINESS_WEEK:
    case ALL_TIME:
    case CUSTOM_DATE:
    default:
        throw new IllegalArgumentException("Unsupported DateRange type: " + dateRange);
    }

    return new DateRange(startDate, endDate);
}

From source file:com.google.api.ads.adwords.awreporting.model.entities.DateRangeAndType.java

License:Open Source License

/**
 * Parse DateRange in ReportDefinitionDateRangeType enum format.
 *//* w ww  .j a va 2s  . co  m*/
private static DateRangeAndType parseEnumFormat(ReportDefinitionDateRangeType type) {
    LocalDate today = LocalDate.now();
    LocalDate startDate;
    LocalDate endDate;
    switch (type) {
    case TODAY:
        startDate = endDate = today;
        break;
    case YESTERDAY:
        startDate = endDate = today.minusDays(1);
        break;
    case LAST_7_DAYS:
        startDate = today.minusDays(7);
        endDate = today.minusDays(1);
        break;
    case LAST_WEEK:
        LocalDate.Property lastWeekProp = today.minusWeeks(1).dayOfWeek();
        startDate = lastWeekProp.withMinimumValue();
        endDate = lastWeekProp.withMaximumValue();
        break;
    case THIS_MONTH:
        LocalDate.Property thisMonthProp = today.dayOfMonth();
        startDate = thisMonthProp.withMinimumValue();
        endDate = thisMonthProp.withMaximumValue();
        break;
    case LAST_MONTH:
        LocalDate.Property lastMonthProp = today.minusMonths(1).dayOfMonth();
        startDate = lastMonthProp.withMinimumValue();
        endDate = lastMonthProp.withMaximumValue();
        break;
    case LAST_14_DAYS:
        startDate = today.minusDays(14);
        endDate = today.minusDays(1);
        break;
    case LAST_30_DAYS:
        startDate = today.minusDays(30);
        endDate = today.minusDays(1);
        break;
    case THIS_WEEK_SUN_TODAY:
        // Joda-Time uses the ISO standard Monday to Sunday week.
        startDate = today.minusWeeks(1).dayOfWeek().withMaximumValue();
        endDate = today;
        break;
    case THIS_WEEK_MON_TODAY:
        startDate = today.dayOfWeek().withMinimumValue();
        endDate = today;
        break;
    case LAST_WEEK_SUN_SAT:
        startDate = today.minusWeeks(2).dayOfWeek().withMaximumValue();
        endDate = today.minusWeeks(1).dayOfWeek().withMaximumValue().minusDays(1);
        break;
    // Don't support the following enums
    case LAST_BUSINESS_WEEK:
    case ALL_TIME:
    case CUSTOM_DATE:
    default:
        throw new IllegalArgumentException("Unsupported DateRange type: " + type.value());
    }

    return new DateRangeAndType(startDate, endDate, type);
}

From source file:com.gst.infrastructure.sms.domain.SmsMessage.java

License:Apache License

private SmsMessage(String externalId, final Group group, final Client client, final Staff staff,
        final SmsMessageStatusType statusType, final String message, final String mobileNo,
        final SmsCampaign smsCampaign) {
    this.externalId = externalId;
    this.group = group;
    this.client = client;
    this.staff = staff;
    this.statusType = statusType.getValue();
    this.mobileNo = mobileNo;
    this.message = message;
    this.smsCampaign = smsCampaign;
    this.submittedOnDate = LocalDate.now().toDate();
}

From source file:com.gst.portfolio.group.service.GroupingTypesWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

@Override
public CommandProcessingResult assignGroupOrCenterStaff(final Long groupId, final JsonCommand command) {

    this.context.authenticatedUser();

    final Map<String, Object> actualChanges = new LinkedHashMap<>(5);

    this.fromApiJsonDeserializer.validateForAssignStaff(command.json());

    final Group groupForUpdate = this.groupRepository.findOneWithNotFoundDetection(groupId);

    Staff staff = null;// www  . j a v a 2 s. com
    final Long staffId = command.longValueOfParameterNamed(GroupingTypesApiConstants.staffIdParamName);
    final boolean inheritStaffForClientAccounts = command
            .booleanPrimitiveValueOfParameterNamed(GroupingTypesApiConstants.inheritStaffForClientAccounts);
    staff = this.staffRepository.findByOfficeHierarchyWithNotFoundDetection(staffId,
            groupForUpdate.getOffice().getHierarchy());
    groupForUpdate.updateStaff(staff);

    if (inheritStaffForClientAccounts) {
        LocalDate loanOfficerReassignmentDate = LocalDate.now();
        /*
         * update loan officer for client and update loan officer for
         * clients loans and savings
         */
        Set<Client> clients = groupForUpdate.getClientMembers();
        if (clients != null) {
            for (Client client : clients) {
                client.updateStaff(staff);
                if (this.loanRepositoryWrapper.doNonClosedLoanAccountsExistForClient(client.getId())) {
                    for (final Loan loan : this.loanRepositoryWrapper.findLoanByClientId(client.getId())) {
                        if (loan.isDisbursed() && !loan.isClosed()) {
                            loan.reassignLoanOfficer(staff, loanOfficerReassignmentDate);
                        }
                    }
                }
                if (this.savingsAccountRepositoryWrapper
                        .doNonClosedSavingAccountsExistForClient(client.getId())) {
                    for (final SavingsAccount savingsAccount : this.savingsAccountRepositoryWrapper
                            .findSavingAccountByClientId(client.getId())) {
                        if (!savingsAccount.isClosed()) {
                            savingsAccount.reassignSavingsOfficer(staff, loanOfficerReassignmentDate);
                        }
                    }
                }
            }
        }
    }
    this.groupRepository.saveAndFlush(groupForUpdate);

    actualChanges.put(GroupingTypesApiConstants.staffIdParamName, staffId);

    return new CommandProcessingResultBuilder() //
            .withOfficeId(groupForUpdate.officeId()) //
            .withEntityId(groupForUpdate.getId()) //
            .withGroupId(groupId) //
            .with(actualChanges) //
            .build();
}

From source file:com.gst.portfolio.interestratechart.incentive.ClientAttributeIncentiveCalculation.java

License:Apache License

@Override
public BigDecimal calculateIncentive(IncentiveDTO incentiveDTO) {
    final Client client = incentiveDTO.client();
    BigDecimal interest = incentiveDTO.interest();
    final InterestIncentivesFields incentivesFields = incentiveDTO.incentives();
    boolean applyIncentive = false;
    switch (incentivesFields.attributeName()) {
    case GENDER:/* ww  w.j  a va 2  s .c  om*/
        if (client.genderId() != null) {
            applyIncentive = applyIncentive(incentivesFields.conditionType(),
                    Long.valueOf(incentivesFields.attributeValue()), client.genderId());
        }
        break;
    case AGE:
        if (client.dateOfBirth() != null) {
            final LocalDate dobLacalDate = LocalDate.fromDateFields(client.dateOfBirth());
            final int age = Years.yearsBetween(dobLacalDate, LocalDate.now()).getYears();
            applyIncentive = applyIncentive(incentivesFields.conditionType(),
                    Long.valueOf(incentivesFields.attributeValue()), Long.valueOf(age));
        }
        break;
    case CLIENT_TYPE:
        if (client.clientTypeId() != null) {
            applyIncentive = applyIncentive(incentivesFields.conditionType(),
                    Long.valueOf(incentivesFields.attributeValue()), client.clientTypeId());
        }
        break;
    case CLIENT_CLASSIFICATION:
        if (client.clientClassificationId() != null) {
            applyIncentive = applyIncentive(incentivesFields.conditionType(),
                    Long.valueOf(incentivesFields.attributeValue()), client.clientClassificationId());
        }
        break;

    default:
        break;

    }
    if (applyIncentive) {
        switch (incentivesFields.incentiveType()) {
        case FIXED:
            interest = incentivesFields.amount();
            break;
        case INCENTIVE:
            interest = interest.add(incentivesFields.amount());
            break;
        default:
            break;

        }
    }

    return interest;
}

From source file:com.gst.portfolio.loanaccount.domain.Loan.java

License:Apache License

public LoanTransaction waiveLoanCharge(final LoanCharge loanCharge,
        final LoanLifecycleStateMachine loanLifecycleStateMachine, final Map<String, Object> changes,
        final List<Long> existingTransactionIds, final List<Long> existingReversedTransactionIds,
        final Integer loanInstallmentNumber, final ScheduleGeneratorDTO scheduleGeneratorDTO,
        final Money accruedCharge, final AppUser currentUser) {

    validateLoanIsNotClosed(loanCharge);

    final Money amountWaived = loanCharge.waive(loanCurrency(), loanInstallmentNumber);

    changes.put("amount", amountWaived.getAmount());

    Money unrecognizedIncome = amountWaived.zero();
    Money chargeComponent = amountWaived;
    if (isPeriodicAccrualAccountingEnabledOnLoanProduct()) {
        Money receivableCharge = Money.zero(getCurrency());
        if (loanInstallmentNumber != null) {
            receivableCharge = accruedCharge.minus(
                    loanCharge.getInstallmentLoanCharge(loanInstallmentNumber).getAmountPaid(getCurrency()));
        } else {//from www.  ja  va2 s.c  o m
            receivableCharge = accruedCharge.minus(loanCharge.getAmountPaid(getCurrency()));
        }
        if (receivableCharge.isLessThanZero()) {
            receivableCharge = amountWaived.zero();
        }
        if (amountWaived.isGreaterThan(receivableCharge)) {
            chargeComponent = receivableCharge;
            unrecognizedIncome = amountWaived.minus(receivableCharge);
        }
    }
    Money feeChargesWaived = chargeComponent;
    Money penaltyChargesWaived = Money.zero(loanCurrency());
    if (loanCharge.isPenaltyCharge()) {
        penaltyChargesWaived = chargeComponent;
        feeChargesWaived = Money.zero(loanCurrency());
    }

    LocalDate transactionDate = getDisbursementDate();
    if (loanCharge.isDueDateCharge()) {
        if (loanCharge.getDueLocalDate().isAfter(DateUtils.getLocalDateOfTenant())) {
            transactionDate = DateUtils.getLocalDateOfTenant();
        } else {
            transactionDate = loanCharge.getDueLocalDate();
        }
    } else if (loanCharge.isInstalmentFee()) {
        transactionDate = loanCharge.getInstallmentLoanCharge(loanInstallmentNumber).getRepaymentInstallment()
                .getDueDate();
    }

    scheduleGeneratorDTO.setRecalculateFrom(transactionDate);

    updateSummaryWithTotalFeeChargesDueAtDisbursement(deriveSumTotalOfChargesDueAtDisbursement());

    existingTransactionIds.addAll(findExistingTransactionIds());
    existingReversedTransactionIds.addAll(findExistingReversedTransactionIds());

    final LoanTransaction waiveLoanChargeTransaction = LoanTransaction.waiveLoanCharge(this, getOffice(),
            amountWaived, transactionDate, feeChargesWaived, penaltyChargesWaived, unrecognizedIncome,
            DateUtils.getLocalDateTimeOfTenant(), currentUser);
    final LoanChargePaidBy loanChargePaidBy = new LoanChargePaidBy(waiveLoanChargeTransaction, loanCharge,
            waiveLoanChargeTransaction.getAmount(getCurrency()).getAmount(), loanInstallmentNumber);
    waiveLoanChargeTransaction.getLoanChargesPaid().add(loanChargePaidBy);
    addLoanTransaction(waiveLoanChargeTransaction);
    if (this.repaymentScheduleDetail().isInterestRecalculationEnabled() && (loanCharge.getDueLocalDate() == null
            || LocalDate.now().isAfter(loanCharge.getDueLocalDate()))) {
        regenerateRepaymentScheduleWithInterestRecalculation(scheduleGeneratorDTO, currentUser);
    }
    // Waive of charges whose due date falls after latest 'repayment'
    // transaction dont require entire loan schedule to be reprocessed.
    final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor = this.transactionProcessorFactory
            .determineProcessor(this.transactionProcessingStrategy);
    if (!loanCharge.isDueAtDisbursement() && loanCharge.isPaidOrPartiallyPaid(loanCurrency())) {
        /****
         * TODO Vishwas Currently we do not allow waiving fully paid loan
         * charge and waiving partially paid loan charges only waives the
         * remaining amount.
         * 
         * Consider removing this block of code or logically completing it
         * for the future by getting the list of affected Transactions
         ***/
        final List<LoanTransaction> allNonContraTransactionsPostDisbursement = retreiveListOfTransactionsPostDisbursement();
        loanRepaymentScheduleTransactionProcessor.handleTransaction(getDisbursementDate(),
                allNonContraTransactionsPostDisbursement, getCurrency(), getRepaymentScheduleInstallments(),
                charges());
    } else {
        // reprocess loan schedule based on charge been waived.
        final LoanRepaymentScheduleProcessingWrapper wrapper = new LoanRepaymentScheduleProcessingWrapper();
        wrapper.reprocess(getCurrency(), getDisbursementDate(), getRepaymentScheduleInstallments(), charges());
    }

    updateLoanSummaryDerivedFields();

    doPostLoanTransactionChecks(waiveLoanChargeTransaction.getTransactionDate(), loanLifecycleStateMachine);

    return waiveLoanChargeTransaction;
}