Java Code Examples for java.time.LocalDate#minusMonths()

The following examples show how to use java.time.LocalDate#minusMonths() . 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: RollConventionTest.java    From Strata with Apache License 2.0 5 votes vote down vote up
@Test
public void test_ofDayOfMonth_previous_oneDay() {
  for (int start = 1; start <= 5; start++) {
    for (int i = 1; i <= 30; i++) {
      RollConvention test = RollConvention.ofDayOfMonth(i);
      LocalDate expected = date(2014, JULY, i);
      if (i >= start) {
        expected = expected.minusMonths(1);
      }
      assertThat(test.previous(date(2014, JULY, start), P1D)).isEqualTo(expected);
    }
  }
}
 
Example 2
Source File: LocalDateIMMDateCalculator.java    From objectlabkit with Apache License 2.0 5 votes vote down vote up
private LocalDate calculateIMMMonth(final boolean requestNextIMM, final LocalDate startDate, final Month month) {
    int monthOffset;
    LocalDate date = startDate;
    switch (month) {
    case MARCH:
    case JUNE:
    case SEPTEMBER:
    case DECEMBER:
        final LocalDate immDate = calculate3rdWednesday(date);
        if (requestNextIMM && !date.isBefore(immDate)) {
            date = date.plusMonths(MONTHS_IN_QUARTER);
        } else if (!requestNextIMM && !date.isAfter(immDate)) {
            date = date.minusMonths(MONTHS_IN_QUARTER);
        }
        break;

    default:
        if (requestNextIMM) {
            monthOffset = (MONTH_IN_YEAR - month.getValue()) % MONTHS_IN_QUARTER;
            date = date.plusMonths(monthOffset);
        } else {
            monthOffset = month.getValue() % MONTHS_IN_QUARTER;
            date = date.minusMonths(monthOffset);
        }
        break;
    }
    return date;
}
 
Example 3
Source File: FixedCouponBondTest.java    From Strata with Apache License 2.0 5 votes vote down vote up
@Test
public void test_resolve() {
  FixedCouponBond base = sut();
  ResolvedFixedCouponBond resolved = base.resolve(REF_DATA);
  assertThat(resolved.getLegalEntityId()).isEqualTo(LEGAL_ENTITY);
  assertThat(resolved.getSettlementDateOffset()).isEqualTo(DATE_OFFSET);
  assertThat(resolved.getYieldConvention()).isEqualTo(YIELD_CONVENTION);
  ImmutableList<FixedCouponBondPaymentPeriod> periodicPayments = resolved.getPeriodicPayments();
  int expNum = 20;
  assertThat(periodicPayments).hasSize(expNum);
  LocalDate unadjustedEnd = END_DATE;
  Schedule unadjusted = PERIOD_SCHEDULE.createSchedule(REF_DATA).toUnadjusted();
  for (int i = 0; i < expNum; ++i) {
    FixedCouponBondPaymentPeriod payment = periodicPayments.get(expNum - 1 - i);
    assertThat(payment.getCurrency()).isEqualTo(EUR);
    assertThat(payment.getNotional()).isEqualTo(NOTIONAL);
    assertThat(payment.getFixedRate()).isEqualTo(FIXED_RATE);
    assertThat(payment.getUnadjustedEndDate()).isEqualTo(unadjustedEnd);
    assertThat(payment.getEndDate()).isEqualTo(BUSINESS_ADJUST.adjust(unadjustedEnd, REF_DATA));
    assertThat(payment.getPaymentDate()).isEqualTo(payment.getEndDate());
    LocalDate unadjustedStart = unadjustedEnd.minusMonths(6);
    assertThat(payment.getUnadjustedStartDate()).isEqualTo(unadjustedStart);
    assertThat(payment.getStartDate()).isEqualTo(BUSINESS_ADJUST.adjust(unadjustedStart, REF_DATA));
    assertThat(payment.getYearFraction()).isEqualTo(unadjusted.getPeriod(expNum - 1 - i).yearFraction(DAY_COUNT, unadjusted));
    assertThat(payment.getDetachmentDate()).isEqualTo(EX_COUPON.adjust(payment.getPaymentDate(), REF_DATA));
    unadjustedEnd = unadjustedStart;
  }
  Payment expectedPayment = Payment.of(CurrencyAmount.of(EUR, NOTIONAL), BUSINESS_ADJUST.adjust(END_DATE, REF_DATA));
  assertThat(resolved.getNominalPayment()).isEqualTo(expectedPayment);
}
 
Example 4
Source File: TCKLocalDate.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusMonths_long_invalidTooLargeMaxAddMax() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusMonths(Long.MAX_VALUE);
}
 
Example 5
Source File: TCKLocalDate.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=DateTimeException.class)
public void test_minusMonths_long_invalidTooLargeMaxAddMax() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusMonths(Long.MAX_VALUE);
}
 
Example 6
Source File: TCKLocalDate.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusMonths_long_invalidTooLargeMaxAddMax() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusMonths(Long.MAX_VALUE);
}
 
Example 7
Source File: TCKLocalDate.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusMonths_long_invalidTooLargeMaxAddMin() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusMonths(Long.MIN_VALUE);
}
 
Example 8
Source File: TCKLocalDate.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusMonths_long_invalidTooLargeMaxAddMax() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusMonths(Long.MAX_VALUE);
}
 
Example 9
Source File: TCKLocalDate.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusMonths_long_invalidTooLargeMaxAddMin() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusMonths(Long.MIN_VALUE);
}
 
Example 10
Source File: TCKLocalDate.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusMonths_long_invalidTooLargeMaxAddMin() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusMonths(Long.MIN_VALUE);
}
 
Example 11
Source File: TCKLocalDate.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=DateTimeException.class)
public void test_minusMonths_long_invalidTooLargeMaxAddMin() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusMonths(Long.MIN_VALUE);
}
 
Example 12
Source File: TCKLocalDate.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusMonths_long_invalidTooLargeMaxAddMin() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusMonths(Long.MIN_VALUE);
}
 
Example 13
Source File: TCKLocalDate.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusMonths_long_invalidTooLargeMaxAddMax() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusMonths(Long.MAX_VALUE);
}
 
Example 14
Source File: TCKLocalDate.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusMonths_long_invalidTooLargeMaxAddMax() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusMonths(Long.MAX_VALUE);
}
 
Example 15
Source File: TCKLocalDate.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusMonths_long_invalidTooLargeMaxAddMax() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusMonths(Long.MAX_VALUE);
}
 
Example 16
Source File: TCKLocalDate.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusMonths_long_invalidTooLargeMaxAddMin() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusMonths(Long.MIN_VALUE);
}
 
Example 17
Source File: TCKLocalDate.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusMonths_long_invalidTooLargeMaxAddMax() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusMonths(Long.MAX_VALUE);
}
 
Example 18
Source File: TCKLocalDate.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusMonths_long_invalidTooLargeMaxAddMax() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusMonths(Long.MAX_VALUE);
}
 
Example 19
Source File: TCKLocalDate.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusMonths_long_invalidTooLargeMaxAddMin() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusMonths(Long.MIN_VALUE);
}
 
Example 20
Source File: DateUtil.java    From notes with Apache License 2.0 2 votes vote down vote up
/**
 * 获取当天上个月的日期
 * @param minusMonth  为正数,如果为负数代表增加月份
 * @return: java.util.Date
 * @author: fruiqi
 * @date: 19-5-9 上午11:29
 */
public static Date acquireMonthByMinus(int minusMonth) {
	LocalDate now = LocalDate.now();
	LocalDate lastMonth = now.minusMonths(minusMonth);
	return acquireDateByLocalDate(lastMonth);
}