Java Code Examples for java.time.LocalDate#minus()
The following examples show how to use
java.time.LocalDate#minus() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RangeBasicTests.java From morpheus-core with Apache License 2.0 | 6 votes |
@Test(dataProvider = "localDateRanges") public void testRangeOfLocalDates(LocalDate start, LocalDate end, Period step, boolean parallel) { final Range<LocalDate> range = Range.of(start, end, step); final Array<LocalDate> array = range.toArray(parallel); final boolean ascend = start.isBefore(end); final int expectedLength = (int)Math.ceil(Math.abs((double)ChronoUnit.DAYS.between(start, end)) / (double)step.getDays()); Assert.assertEquals(array.length(), expectedLength); Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_DATE); Assert.assertTrue(!array.style().isSparse()); Assert.assertEquals(range.start(), start, "The range start"); Assert.assertEquals(range.end(), end, "The range end"); LocalDate expected = null; for (int i=0; i<array.length(); ++i) { final LocalDate actual = array.getValue(i); expected = expected == null ? start : ascend ? expected.plus(step) : expected.minus(step); Assert.assertEquals(actual, expected, "Value matches at " + i); Assert.assertTrue(ascend ? actual.compareTo(start) >=0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + i); } }
Example 2
Source File: RangeFilterTests.java From morpheus-core with Apache License 2.0 | 6 votes |
@Test(dataProvider = "LocalDateRanges") public void testRangeOfLocalDates(LocalDate start, LocalDate end, Period step, boolean parallel) { final boolean ascend = start.isBefore(end); final Range<LocalDate> range = Range.of(start, end, step, v -> v.getDayOfWeek() == DayOfWeek.MONDAY); final Array<LocalDate> array = range.toArray(parallel); final LocalDate first = array.first(v -> true).map(ArrayValue::getValue).get(); final LocalDate last = array.last(v -> true).map(ArrayValue::getValue).get(); Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_DATE); Assert.assertTrue(!array.style().isSparse()); Assert.assertEquals(range.start(), start, "The range start"); Assert.assertEquals(range.end(), end, "The range end"); int index = 0; LocalDate value = first; while (ascend ? value.isBefore(last) : value.isAfter(last)) { final LocalDate actual = array.getValue(index); Assert.assertEquals(actual, value, "Value matches at " + index); Assert.assertTrue(ascend ? actual.compareTo(start) >= 0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + index); value = ascend ? value.plus(step) : value.minus(step); while (value.getDayOfWeek() == DayOfWeek.MONDAY) value = ascend ? value.plus(step) : value.minus(step); index++; } }
Example 3
Source File: LocalDateType.java From jdmn with Apache License 2.0 | 5 votes |
@Override public LocalDate dateSubtractDuration(LocalDate date, TemporalAmount duration) { if (date == null || duration == null) { return null; } try { return date.minus(duration); } catch (Exception e) { String message = String.format("dateSubtractDuration(%s, %s)", date, duration); logError(message, e); return null; } }
Example 4
Source File: LocalDateType.java From jdmn with Apache License 2.0 | 5 votes |
@Override public LocalDate dateSubtractDuration(LocalDate date, Duration duration) { if (date == null || duration == null) { return null; } try { return date.minus(toTemporalPeriod(duration)); } catch (Exception e) { String message = String.format("dateSubtract(%s, %s)", date, duration); logError(message, e); return null; } }
Example 5
Source File: DayRollConventions.java From Strata with Apache License 2.0 | 5 votes |
@Override public LocalDate previous(LocalDate date, Frequency periodicFrequency) { ArgChecker.notNull(date, "date"); ArgChecker.notNull(periodicFrequency, "periodicFrequency"); LocalDate calculated = date.minus(periodicFrequency); return calculated.with(TemporalAdjusters.previousOrSame(day)); }
Example 6
Source File: DayCountTest.java From Strata with Apache License 2.0 | 5 votes |
@Test public void test_actActIcma_longFinalStub_eomFlagEom_short() { // nominals, 2011-08-31 (P91D) 2011-11-30 (P91D) 2012-02-29 LocalDate start = LocalDate.of(2011, 8, 31); LocalDate periodEnd = LocalDate.of(2012, 1, 31); LocalDate end = LocalDate.of(2011, 11, 12); // before first nominal ScheduleInfo info = new Info(start.minus(P3M), periodEnd, periodEnd, true, P3M); assertThat(ACT_ACT_ICMA.yearFraction(start, end, info)).isEqualTo((73d / (91d * 4d))); }
Example 7
Source File: DayCountTest.java From Strata with Apache License 2.0 | 5 votes |
@Test public void test_actActIcma_longFinalStub_eomFlagEom_long() { // nominals, 2011-08-31 (P91D) 2011-11-30 (P91D) 2012-02-29 LocalDate start = LocalDate.of(2011, 8, 31); LocalDate periodEnd = LocalDate.of(2012, 1, 31); LocalDate end = LocalDate.of(2012, 1, 12); // after first nominal ScheduleInfo info = new Info(start.minus(P3M), periodEnd, periodEnd, true, P3M); assertThat(ACT_ACT_ICMA.yearFraction(start, end, info)).isEqualTo((91d / (91d * 4d)) + (43d / (91d * 4d))); }
Example 8
Source File: DayCountTest.java From Strata with Apache License 2.0 | 5 votes |
@Test public void test_actActIcma_longFinalStub_notEomFlagEom_short() { // nominals, 2012-02-29 (P90D) 2012-05-29 (P92D) 2012-08-29 LocalDate start = LocalDate.of(2012, 2, 29); LocalDate periodEnd = LocalDate.of(2012, 7, 31); LocalDate end = LocalDate.of(2012, 4, 1); // before first nominal ScheduleInfo info = new Info(start.minus(P3M), periodEnd, periodEnd, false, P3M); assertThat(ACT_ACT_ICMA.yearFraction(start, end, info)).isEqualTo((32d / (90d * 4d))); }
Example 9
Source File: DayCountTest.java From Strata with Apache License 2.0 | 5 votes |
@Test public void test_actActIcma_longFinalStub_notEomFlagEom_long() { // nominals, 2012-02-29 (P90D) 2012-05-29 (P92D) 2012-08-29 LocalDate start = LocalDate.of(2012, 2, 29); LocalDate periodEnd = LocalDate.of(2012, 7, 31); LocalDate end = LocalDate.of(2012, 6, 1); // after first nominal ScheduleInfo info = new Info(start.minus(P3M), periodEnd, periodEnd, false, P3M); assertThat(ACT_ACT_ICMA.yearFraction(start, end, info)).isEqualTo((90d / (90d * 4d)) + (3d / (92d * 4d))); }
Example 10
Source File: DayCountTest.java From Strata with Apache License 2.0 | 5 votes |
@Test public void test_actAct_isdaTestCase_longFinalStub() { LocalDate start = LocalDate.of(1999, 11, 30); LocalDate end = LocalDate.of(2000, 4, 30); ScheduleInfo info = new Info(start.minus(P3M), end, end, true, P3M); assertThat(ACT_ACT_ISDA.yearFraction(start, end)).isEqualTo((32d / 365d) + (120d / 366d)); assertThat(ACT_ACT_ICMA.yearFraction(start, end, info)).isEqualTo((91d / (91d * 4d)) + (61d / (92d * 4))); assertThat(ACT_ACT_AFB.yearFraction(start, end)).isEqualTo((152d / 366d)); }
Example 11
Source File: IsdaCompliantDiscountCurveCalibrator.java From Strata with Apache License 2.0 | 5 votes |
public BasicFixedLeg( LocalDate curveSpotDate, LocalDate maturityDate, Period swapInterval, DayCount swapDCC, DayCount curveDcc, BusinessDayAdjustment busAdj, ReferenceData refData) { List<LocalDate> list = new ArrayList<>(); LocalDate tDate = maturityDate; int step = 1; while (tDate.isAfter(curveSpotDate)) { list.add(tDate); tDate = maturityDate.minus(swapInterval.multipliedBy(step++)); } // remove spotDate from list, if it ends up there list.remove(curveSpotDate); nPayment = list.size(); swapPaymentTime = new double[nPayment]; yearFraction = new double[nPayment]; LocalDate prev = curveSpotDate; int j = nPayment - 1; for (int i = 0; i < nPayment; i++, j--) { LocalDate current = list.get(j); LocalDate adjCurr = busAdj.adjust(current, refData); yearFraction[i] = swapDCC.relativeYearFraction(prev, adjCurr); swapPaymentTime[i] = curveDcc.relativeYearFraction(curveSpotDate, adjCurr); // Payment times always good business days prev = adjCurr; } }
Example 12
Source File: UseLocalDate.java From tutorials with MIT License | 4 votes |
LocalDate getPreviousDay(LocalDate localDate) { return localDate.minus(1, ChronoUnit.DAYS); }
Example 13
Source File: DateUtils.java From spring-boot-start-current with Apache License 2.0 | 2 votes |
/** * 获取前 i 天日期 * * @return */ public static LocalDate getPreviousDay ( int i ) { LocalDate today = LocalDate.now(); return today.minus( i , ChronoUnit.DAYS ); }