Period membershipLength = Period.ofYears(1); LocalDate membershipStart = ...; LocalDate membershipEnd = membershipStart.plus(membershipLength); boolean isMember = !LocalDate.now().isAfter(membershipEnd);
@Test(dataProvider = "stubIbor") public void test_stub_ibor(ThreeLegBasisSwapConvention convention, Tenor tenor) { LocalDate tradeDate = LocalDate.of(2015, 10, 20); SwapTrade swap = convention.createTrade(tradeDate, tenor, BuySell.BUY, 1, 0.01, REF_DATA); ResolvedSwap swapResolved = swap.getProduct().resolve(REF_DATA); LocalDate endDate = swapResolved.getLeg(PayReceive.PAY).get().getEndDate(); assertTrue(endDate.isAfter(tradeDate.plus(tenor).minusMonths(1))); assertTrue(endDate.isBefore(tradeDate.plus(tenor).plusMonths(1))); }
protected boolean isValidDate(Chronology chrono, LocalDate date, int offset, ChronoUnit unit) { return date != null && isValidDate(chrono, date.plus(offset, unit)); }
private static String addDays(String date, int days) { final LocalDate d = parseDate(date); return DEFAULT_FOMATTER.format(d.plus(Period.ofDays(days))); }
private void updateDayNameCells() { int weekFirstDay = WeekFields.of(getLocale()).getFirstDayOfWeek().getValue(); LocalDate date = LocalDate.of(2009, 7, 12 + weekFirstDay); for (int i = 0; i < daysPerWeek; i++) { String name = weekDayNameFormatter.withLocale(getLocale()).format(date.plus(i, DAYS)); // Fix Chinese environment week display incorrectly // Take the last character of the Chinese weekday names if (weekDayNameFormatter.getLocale() == java.util.Locale.CHINA) { name = name.substring(name.length() - 1).toUpperCase(); } else { name = name.substring(0, 1).toUpperCase(); } weekDaysCells.get(i).setText(name); } }
void updateWeekNumberDateCells() { if (datePicker.isShowWeekNumbers()) { final Locale locale = getLocale(); LocalDate firstDayOfMonth = selectedYearMonth.get().atDay(1); for (int i = 0; i < 6; i++) { LocalDate date = firstDayOfMonth.plus(i, WEEKS); String weekNumber = weekNumberFormatter.withLocale(locale) .withDecimalStyle(DecimalStyle.of(locale)) .format(date); weekNumberCells.get(i).setText(weekNumber); } } }
@Test void shouldAddToLocalDate() { assertEquals( LocalDate.of( 2017, 12, 5 ), LocalDate.of( 2017, 12, 4 ).plus( parse( "PT24H" ) ), "seconds" ); assertEquals( LocalDate.of( 2017, 12, 3 ), LocalDate.of( 2017, 12, 4 ).minus( parse( "PT24H" ) ), "seconds" ); assertEquals( LocalDate.of( 2017, 12, 4 ), LocalDate.of( 2017, 12, 4 ).plus( parse( "PT24H-1S" ) ), "seconds" ); assertEquals( LocalDate.of( 2017, 12, 4 ), LocalDate.of( 2017, 12, 4 ).minus( parse( "PT24H-1S" ) ), "seconds" ); assertEquals( LocalDate.of( 2017, 12, 5 ), LocalDate.of( 2017, 12, 4 ).plus( parse( "P1D" ) ), "days" ); assertEquals( LocalDate.of( 2017, 12, 3 ), LocalDate.of( 2017, 12, 4 ).minus( parse( "P1D" ) ), "days" ); }
private void goToDayCell(DateCell dateCell, int offset, ChronoUnit unit, boolean focusDayCell) { YearMonth yearMonth = selectedYearMonth.get().plus(offset, unit); goToDate(dayCellDate(dateCell).plus(offset, unit).withYear(yearMonth.getYear()), focusDayCell); }
@Test public void rangeQueries() { Instant instant = Instant.ofEpochMilli(System.currentTimeMillis()); LocalDate localDate = LocalDate.of(1995, 10, 15); LocalDateTime localDateTime = LocalDateTime.of(2016, 4, 10, 14, 15, 16, 123 * 1000000); LocalTime localTime = LocalTime.of(10, 29, 15, 848493); for (int i = 0; i < 10; i++) { createEntity(getDs(), instant.plus(i, DAYS), localDate.plus(i, DAYS), localDateTime.plus(i, DAYS), localTime.plus(i, ChronoUnit.HOURS)); } Assert.assertEquals(2L, getDs().find(Java8Entity.class).field("instant").lessThanOrEq(instant.plus(1, DAYS)).count()); Assert.assertEquals(1L, getDs().find(Java8Entity.class).field("localDate").equal(localDate.plus(1, DAYS)).count()); Assert.assertEquals(0L, getDs().find(Java8Entity.class).field("localDate").equal(localDate.minus(1, DAYS)).count()); Assert.assertEquals(9L, getDs().find(Java8Entity.class).field("localDateTime") .notEqual(localDateTime.plus(6, DAYS)).count()); }
if (dateUnit == MONTH) { start = startDate.withDayOfMonth(1); end = endDate.withDayOfMonth(1).plus(1, ChronoUnit.MONTHS); } else if (dateUnit == WEEK) { TemporalField fieldUS = WeekFields.of(Locale.US).dayOfWeek(); start = startDate.with(fieldUS, 1); end = endDate.with(fieldUS, 1).plus(1, ChronoUnit.MONTHS); } else { start = startDate;
if (dateUnit == MONTH) { start = startDate.withDayOfMonth(1); end = endDate.withDayOfMonth(1).plus(1, ChronoUnit.MONTHS); } else if (dateUnit == WEEK) { TemporalField fieldUS = WeekFields.of(Locale.US).dayOfWeek(); start = startDate.with(fieldUS, 1); end = endDate.with(fieldUS, 1).plus(1, ChronoUnit.MONTHS); } else if (dateUnit == DAY) { start = startDate;
/** * Calculates the expiration date of a swaption from the calibration date and the underlying swap convention. * * @param bda the business day convention * @param calibrationDate the calibration date * @param expiry the period to expiry * @return the date */ private LocalDate expirationDate(BusinessDayAdjustment bda, LocalDate calibrationDate, Period expiry) { return bda.adjust(calibrationDate.plus(expiry), refData); }
@Override public IborFixingDepositTrade createTrade( LocalDate tradeDate, Period depositPeriod, BuySell buySell, double notional, double fixedRate, ReferenceData refData) { LocalDate startDate = calculateSpotDateFromTradeDate(tradeDate, refData); LocalDate endDate = startDate.plus(depositPeriod); return toTrade(tradeDate, startDate, endDate, buySell, notional, fixedRate); }
@Override public LocalDate calculateReferenceDateFromTradeDate( LocalDate tradeDate, Period minimumPeriod, int sequenceNumber, ReferenceData refData) { LocalDate earliestDate = tradeDate.plus(minimumPeriod); LocalDate referenceDate = dateSequence.nthOrSame(earliestDate, sequenceNumber); return businessDayAdjustment.adjust(referenceDate, refData); }
LocalDate date1 = new LocalDate("2011-12-12"); LocalDate date2 = new LocalDate("2012-11-11"); while(date1.isBefore(date2)){ System.out.println(date1.toString("MMM/yyyy")); date1 = date1.plus(Period.months(1)); }
public void test_actActIcma_longInitialStub_eomFlagEom_short() { // nominals, 2011-08-31 (P91D) 2011-11-30 (P91D) 2012-02-29 LocalDate start = LocalDate.of(2011, 10, 1); LocalDate periodEnd = LocalDate.of(2012, 2, 29); LocalDate end = LocalDate.of(2011, 11, 12); // before first nominal ScheduleInfo info = new Info(start, periodEnd.plus(P3M), periodEnd, true, P3M); assertEquals(ACT_ACT_ICMA.yearFraction(start, end, info), (42d / (91d * 4d)), TOLERANCE_ZERO); }
public void test_actActIcma_longInitialStub_notEomFlagEom_short() { // nominals, 2011-08-29 (P92D) 2011-11-29 (P92D) 2012-02-29 LocalDate start = LocalDate.of(2011, 10, 1); LocalDate periodEnd = LocalDate.of(2012, 2, 29); LocalDate end = LocalDate.of(2011, 11, 12); // before first nominal ScheduleInfo info = new Info(start, periodEnd.plus(P3M), periodEnd, false, P3M); assertEquals(ACT_ACT_ICMA.yearFraction(start, end, info), (42d / (92d * 4d)), TOLERANCE_ZERO); }
public void test_actAct_isdaTestCase_normal() { LocalDate start = LocalDate.of(2003, 11, 1); LocalDate end = LocalDate.of(2004, 5, 1); ScheduleInfo info = new Info(start, end.plus(P6M), end, true, P6M); assertEquals(ACT_ACT_ISDA.yearFraction(start, end), (61d / 365d) + (121d / 366d), TOLERANCE_ZERO); assertEquals(ACT_ACT_ICMA.yearFraction(start, end, info), (182d / (182d * 2d)), TOLERANCE_ZERO); assertEquals(ACT_ACT_AFB.yearFraction(start, end), (182d / 366d), TOLERANCE_ZERO); }
@Override public DatedParameterMetadata metadata(LocalDate valuationDate, ReferenceData refData) { return LabelDateParameterMetadata.of( HolidayCalendars.SAT_SUN.nextOrSame(valuationDate.plus(periodToEnd)), periodToEnd.toString()); }
public void test_metadata_end() { FxSwapCurveNode node = FxSwapCurveNode.of(TEMPLATE, QUOTE_ID_PTS); LocalDate valuationDate = LocalDate.of(2015, 1, 22); LocalDate endDate = CONVENTION.getBusinessDayAdjustment() .adjust(CONVENTION.getSpotDateOffset().adjust(valuationDate, REF_DATA).plus(FAR_PERIOD), REF_DATA); ParameterMetadata metadata = node.metadata(valuationDate, REF_DATA); assertEquals(((TenorDateParameterMetadata) metadata).getDate(), endDate); assertEquals(((TenorDateParameterMetadata) metadata).getTenor(), Tenor.of(FAR_PERIOD)); }