private List<ReportEntry> fillForEmptyPeriods( List<ReportEntry> inputEntries, Pair<LocalDate, LocalDate> interval) { Optional<String> aRosterTypeCode = inputEntries.stream().map(ReportEntry::getRosterTypeCode).findAny(); if (!aRosterTypeCode.isPresent()) { return inputEntries; } List<ReportEntry> result = inputEntries.stream().collect(Collectors.toList()); for (LocalDate period = interval.getLeft(); period.isBefore(interval.getRight()); period = period.plusMonths(1)) { result.add( new ReportEntry( beneficiary, aRosterTypeCode.get(), AmountType.PAYMENT, YearMonth.from(period), BigDecimal.ZERO)); result.add( new ReportEntry( beneficiary, "UNKNOWN", AmountType.REFUND, YearMonth.from(period), BigDecimal.ZERO)); } return result; }
@Test public void testGenerateScheduleInterestOnlyMonthly() { AmortizationAttributes amAttrs = generateAmortizationAttributesObjectTemplate(); amAttrs.setLoanAmount(ofUSD(10000)); amAttrs.setInterestRateAsPercent(10.); amAttrs.setInterestOnly(true); amAttrs.setPaymentFrequency(TimePeriod.Monthly.getPeriodsPerYear()); int termInMonths = 12; amAttrs.setTermInMonths(termInMonths); amAttrs.setAdjustmentDate(LocalDate.of(2016, Month.JANUARY, 1)); amAttrs.setRegularPayment(ofUSD(0)); List<ScheduledPayment> schedule = AmortizationCalculator.generateSchedule(amAttrs); assertEquals("Interest only schedule term in months", termInMonths, schedule.size()); MonetaryAmount expectedInterest = ofUSD(83.34); MonetaryAmount expectedPrincipal = ofUSD(0); LocalDate expectedDate = amAttrs.getAdjustmentDate(); int index = 0; for (ScheduledPayment payment : schedule) { expectedDate = expectedDate.plusMonths(1L); assertEquals("Interest only schedule payment number", ++index, payment.getPaymentNumber()); assertEquals("Interest only schedule payment date", expectedDate, payment.getPaymentDate()); assertEquals( "Interest only schedule payment interest", expectedInterest, payment.getInterest()); assertEquals( "Interest only schedule payment principal", expectedPrincipal, payment.getPrincipal()); assertEquals( "Interest only schedule payment total payment", expectedInterest, payment.getPayment()); assertEquals( "Interest only schedule payment loan principal", ofUSD(10000), payment.getBalance()); } }
@Test public void testGetFullAge4LocalDateDetails() { int year = 2010; // 0 周岁 for (int m = 1; m <= 12; m++) { Assert.assertEquals( 0, AgeUtils.getFullAge(LocalDate.of(year, 1, 1), LocalDate.of(year, m, 1))); } // 1 周岁:下一年相同月或此月之后不论哪个月、不论哪一天 LocalDate toDate; int lastDay; for (int m = 1; m <= 12; m++) { toDate = LocalDate.of(year + 1, m, 1); lastDay = toDate.plusMonths(1).minusDays(1).getDayOfMonth(); for (int d = 1; d <= lastDay; d++) { Assert.assertEquals( 1, AgeUtils.getFullAge(LocalDate.of(year, 1, 1), LocalDate.of(year + 1, m, d))); } } // 2 周岁 Assert.assertEquals( 2, AgeUtils.getFullAge(LocalDate.of(year, 1, 1), LocalDate.of(year + 2, 1, 1))); Assert.assertEquals( 2, AgeUtils.getFullAge(LocalDate.of(year, 2, 10), LocalDate.of(year + 2, 2, 10))); Assert.assertEquals( 2, AgeUtils.getFullAge(LocalDate.of(year, 2, 10), LocalDate.of(year + 2, 12, 31))); Assert.assertEquals( 1, AgeUtils.getFullAge(LocalDate.of(year, 2, 10), LocalDate.of(year + 2, 2, 9))); }
/** * Adds the period of this frequency to the specified date. * * <p>This method implements {@link TemporalAmount}. It is not intended to be called directly. Use * {@link LocalDate#plus(TemporalAmount)} instead. * * @param temporal the temporal object to add to * @return the result with this frequency added * @throws DateTimeException if unable to add * @throws ArithmeticException if numeric overflow occurs */ @Override public Temporal addTo(Temporal temporal) { // special case for performance if (temporal instanceof LocalDate) { LocalDate date = (LocalDate) temporal; return date.plusMonths(period.toTotalMonths()).plusDays(period.getDays()); } return period.addTo(temporal); }
public void test_metadata_fixed() { LocalDate nodeDate = VAL_DATE.plusMonths(1); TermDepositCurveNode node = TermDepositCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD).withDate(CurveNodeDate.of(nodeDate)); LocalDate valuationDate = LocalDate.of(2015, 1, 22); DatedParameterMetadata metadata = node.metadata(valuationDate, REF_DATA); assertEquals(metadata.getDate(), nodeDate); assertEquals(metadata.getLabel(), node.getLabel()); }
@Test public void testPaymentDateSemiMonthly() { LocalDate scheduleStartDate = LocalDate.of(2015, Month.DECEMBER, 2); AmortizationAttributes amAttrs = generateAmortizationAttributesObjectTemplate(); amAttrs.setAdjustmentDate(scheduleStartDate); amAttrs.setPaymentFrequency(TimePeriod.SemiMonthly.getPeriodsPerYear()); int termInMonths = 24; amAttrs.setTermInMonths(termInMonths); int dayOfMonthPayment1 = scheduleStartDate.getDayOfMonth(); int dayOfMonthPayment2 = scheduleStartDate.plusDays(14).getDayOfMonth(); List<ScheduledPayment> schedule = AmortizationCalculator.generateSchedule(amAttrs); // First payment of month for (int i = 1; i <= 48; i += 2) { String msg = String.format("First date for semi-monthly payment %d", i); assertEquals( msg, scheduleStartDate.plusMonths(i / 2).plusDays(14), schedule.get(i - 1).getPaymentDate()); assertEquals( "Semi-monthly common day of month", dayOfMonthPayment2, schedule.get(i - 1).getPaymentDate().getDayOfMonth()); } // Second payment of month for (int i = 2; i <= 48; i += 2) { String msg = String.format("Second date for semi-monthly payment %d", i); assertEquals(msg, scheduleStartDate.plusMonths(i / 2), schedule.get(i - 1).getPaymentDate()); assertEquals( "Semi-monthly common day of month", dayOfMonthPayment1, schedule.get(i - 1).getPaymentDate().getDayOfMonth()); } }
@Override public Year get(Integer yearInt) { log.debug("Entering with {}", yearInt); LocalDate date = LocalDate.of(yearInt, java.time.Month.JANUARY, 1); Year year = new Year(); year.setYear(yearInt); for (int i = 0; i < 12; i++) year.getMonths().add(create(date, date.plusMonths(i))); return year; }
static void f1() { LocalDate date = LocalDate.of(2016, Month.JANUARY, 24); int year = date.getYear(); // 2016 Month month = date.getMonth(); // 1月 int dom = date.getDayOfMonth(); // 24 DayOfWeek dow = date.getDayOfWeek(); // 星期天,SUNDAY int len = date.lengthOfMonth(); // 31 (1月份的天数) boolean leap = date.isLeapYear(); // true (是闰年) date = date.withYear(2015); // 2015-01-24 date = date.plusMonths(2); // 2015-03-24 date = date.minusDays(1); // 2015-03-23 System.out.println(dow); }
private void testPaymentDatesWithMonthlyIntervals(int periodsPerYear) { LocalDate scheduleStartDate = LocalDate.of(2015, Month.DECEMBER, 2); AmortizationAttributes amAttrs = generateAmortizationAttributesObjectTemplate(); amAttrs.setAdjustmentDate(scheduleStartDate); amAttrs.setPaymentFrequency(periodsPerYear); int termInMonths = 24; amAttrs.setTermInMonths(termInMonths); List<ScheduledPayment> schedule = AmortizationCalculator.generateSchedule(amAttrs); for (int i = 1; i <= termInMonths / (12 / periodsPerYear); i++) { String msg = String.format("Date for payment %d when %d payments a year", i, periodsPerYear); assertEquals( msg, scheduleStartDate.plusMonths(i * (12 / periodsPerYear)), schedule.get(i - 1).getPaymentDate()); } }