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

The following examples show how to use java.time.LocalDate#of() . 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: TCKChronoZonedDateTime.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="calendars")
public void test_badTemporalFieldChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
        TemporalField adjuster = new FixedTemporalField(czdt2);
        if (chrono != chrono2) {
            try {
                czdt.with(adjuster, 1);
                Assert.fail("TemporalField doWith() should have thrown a ClassCastException, " + czdt.getClass()
                        + " can not be cast to " + czdt2.getClass());
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoZonedDateTime<?> result = czdt.with(adjuster, 1);
            assertEquals(result, czdt2, "TemporalField doWith() failed to replace date");
        }
    }
}
 
Example 2
Source File: PolicyElasticRepositoryTest.java    From micronaut-microservices-poc with Apache License 2.0 6 votes vote down vote up
@Test
public void canIndexPolicy() {
    PolicyDocument policyDocument = new PolicyDocument(
            "111-111",
            LocalDate.of(2019, 1, 1),
            LocalDate.of(2019, 12, 31),
            "John Smith",
            "SAFE_HOUSE",
            BigDecimal.valueOf(1000),
            "m.smith"
    );

    PolicyElasticRepository repository = new PolicyElasticRepository(
            new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", el.getHttpPort(), "http"))),
            new JsonConverter(objectMapper())
    );

    repository.save(policyDocument);

    PolicyDocument saved = repository.findByNumber("111-111");

    assertNotNull(saved);
}
 
Example 3
Source File: ImmutableHolidayCalendar.java    From Strata with Apache License 2.0 6 votes vote down vote up
private LocalDate shiftPrev(int baseYear, int baseMonth, int baseDom, int amount) {
  // find data for month
  int index = (baseYear - startYear) * 12 + baseMonth - 1;
  int monthData = lookup[index];
  // loop around amount, the number of days to shift by
  // use domOffset to keep track of day-of-month
  int domOffset = baseDom;
  for (int amt = amount; amt < 0; amt++) {
    // shift to move the target day-of-month into bit-31, removing later days
    int shifted = (monthData << (32 - domOffset));
    // recurse to previous month if no more business days in the month
    if (shifted == 0 || domOffset <= 0) {
      return baseMonth == 1 ? shiftPrev(baseYear - 1, 12, 31, amt) : shiftPrev(baseYear, baseMonth - 1, 31, amt);
    }
    // find most significant bit, which is previous business day
    // use JDK numberOfLeadingZeros() method which is mapped to a fast intrinsic
    domOffset -= (Integer.numberOfLeadingZeros(shifted) + 1);
  }
  return LocalDate.of(baseYear, baseMonth, domOffset + 1);
}
 
Example 4
Source File: TCKLocalizedFieldPrinter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="LocalWeekBasedYearPatterns")
Object[][] provider_patternLocalWeekBasedYearDate() {
    return new Object[][] {
        {"e w Y",  "6 29 2012", LocalDate.of(2012, 7, 20)},
        {"'Date: 'Y', day-of-week: 'e', week-of-year: 'w",
            "Date: 2012, day-of-week: 6, week-of-year: 29", LocalDate.of(2012, 7, 20)},
        {"Y-ww-ee", "2008-01-01", LocalDate.of(2007, 12, 30)},
        {"Y-w-e",   "2008-52-1", LocalDate.of(2008, 12, 21)},
        {"Y-w-e",   "2008-52-7", LocalDate.of(2008, 12, 27)},
        {"Y-ww-e",  "2009-01-1", LocalDate.of(2008, 12, 28)},
        {"Y-w-e",   "2009-1-4",  LocalDate.of(2008, 12, 31)},
        {"Y-w-e",   "2009-1-5", LocalDate.of(2009, 1, 1)},
        {"YYYYYYYYY-w-e",   "000002009-1-5", LocalDate.of(2009, 1, 1)},
   };
}
 
Example 5
Source File: TCKDateTimeParseResolver.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="resolveThreeToDate")
Object[][] data_resolveThreeToDate() {
    return new Object[][]{
            // merge
            {YEAR, 2012, MONTH_OF_YEAR, 2, DAY_OF_MONTH, 1, LocalDate.of(2012, 2, 1)},
            {YEAR, 2012, ALIGNED_WEEK_OF_YEAR, 5, ALIGNED_DAY_OF_WEEK_IN_YEAR, 4, LocalDate.of(2012, 2, 1)},
            {YEAR, 2012, ALIGNED_WEEK_OF_YEAR, 5, DAY_OF_WEEK, 3, LocalDate.of(2012, 2, 1)},

            // cross-check
            {YEAR, 2012, DAY_OF_YEAR, 32, DAY_OF_MONTH, 1, LocalDate.of(2012, 2, 1)},
            {YEAR_OF_ERA, 2012, DAY_OF_YEAR, 32, DAY_OF_MONTH, 1, LocalDate.of(2012, 2, 1)},
            {YEAR, 2012, DAY_OF_YEAR, 32, DAY_OF_WEEK, 3, LocalDate.of(2012, 2, 1)},
            {PROLEPTIC_MONTH, 2012 * 12 + (2 - 1), DAY_OF_MONTH, 25, DAY_OF_WEEK, 6, LocalDate.of(2012, 2, 25)},
    };
}
 
Example 6
Source File: TCKMinguoChronology.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="samples")
Object[][] data_samples() {
    return new Object[][] {
        {MinguoChronology.INSTANCE.date(1, 1, 1), LocalDate.of(1 + YDIFF, 1, 1)},
        {MinguoChronology.INSTANCE.date(1, 1, 2), LocalDate.of(1 + YDIFF, 1, 2)},
        {MinguoChronology.INSTANCE.date(1, 1, 3), LocalDate.of(1 + YDIFF, 1, 3)},

        {MinguoChronology.INSTANCE.date(2, 1, 1), LocalDate.of(2 + YDIFF, 1, 1)},
        {MinguoChronology.INSTANCE.date(3, 1, 1), LocalDate.of(3 + YDIFF, 1, 1)},
        {MinguoChronology.INSTANCE.date(3, 12, 6), LocalDate.of(3 + YDIFF, 12, 6)},
        {MinguoChronology.INSTANCE.date(4, 1, 1), LocalDate.of(4 + YDIFF, 1, 1)},
        {MinguoChronology.INSTANCE.date(4, 7, 3), LocalDate.of(4 + YDIFF, 7, 3)},
        {MinguoChronology.INSTANCE.date(4, 7, 4), LocalDate.of(4 + YDIFF, 7, 4)},
        {MinguoChronology.INSTANCE.date(5, 1, 1), LocalDate.of(5 + YDIFF, 1, 1)},
        {MinguoChronology.INSTANCE.date(100, 3, 3), LocalDate.of(100 + YDIFF, 3, 3)},
        {MinguoChronology.INSTANCE.date(101, 10, 28), LocalDate.of(101 + YDIFF, 10, 28)},
        {MinguoChronology.INSTANCE.date(101, 10, 29), LocalDate.of(101 + YDIFF, 10, 29)},

        {MinguoChronology.INSTANCE.dateYearDay(1916 - YDIFF, 60), LocalDate.of(1916, 2, 29)},
        {MinguoChronology.INSTANCE.dateYearDay(1908 - YDIFF, 60), LocalDate.of(1908, 2, 29)},
        {MinguoChronology.INSTANCE.dateYearDay(2000 - YDIFF, 60), LocalDate.of(2000, 2, 29)},
        {MinguoChronology.INSTANCE.dateYearDay(2400 - YDIFF, 60), LocalDate.of(2400, 2, 29)},

        {MinguoChronology.INSTANCE.dateYearDay(MinguoEra.ROC, 1916 - YDIFF, 60), LocalDate.of(1916, 2, 29)},
        {MinguoChronology.INSTANCE.dateYearDay(MinguoEra.BEFORE_ROC, 4, 60), LocalDate.of(1908, 2, 29)},
        {MinguoChronology.INSTANCE.dateYearDay(MinguoEra.ROC, 2000 - YDIFF, 60), LocalDate.of(2000, 2, 29)},
        {MinguoChronology.INSTANCE.dateYearDay(MinguoEra.ROC, 2400 - YDIFF, 60), LocalDate.of(2400, 2, 29)},

        {MinguoChronology.INSTANCE.date(MinguoEra.ROC, 1916 - YDIFF, 2, 29 ), LocalDate.of(1916, 2, 29)},
        {MinguoChronology.INSTANCE.date(MinguoEra.BEFORE_ROC, 4, 2, 29), LocalDate.of(1908, 2, 29)},
        {MinguoChronology.INSTANCE.date(MinguoEra.ROC, 2000 - YDIFF, 2, 29), LocalDate.of(2000, 2, 29)},
        {MinguoChronology.INSTANCE.date(MinguoEra.ROC, 2400 - YDIFF, 2, 29), LocalDate.of(2400, 2, 29)},
    };
}
 
Example 7
Source File: PeriodDemo.java    From SA47 with The Unlicense 5 votes vote down vote up
public static void main(String[] args) {
	
	LocalDate dateA = LocalDate.of(1978, 8, 26);
	LocalDate dateB = LocalDate.of(1988, 9, 28);
	Period period = Period.between(dateA, dateB);
	System.out.printf("Between %s and %s" + " there are %d years, %d months" + " and %d days%n", dateA, dateB,
			period.getYears(), period.getMonths(), period.getDays());

}
 
Example 8
Source File: MeetupTest.java    From java with MIT License 5 votes vote down vote up
@Ignore("Remove to run test")
@Test
public void testSecondTuesdayOfJune2013() {
    LocalDate expected = LocalDate.of(2013, 6, 11);
    Meetup meetup = new Meetup(6, 2013);
    assertEquals(expected, meetup.day(DayOfWeek.TUESDAY, MeetupSchedule.SECOND));
}
 
Example 9
Source File: FraCurveNodeTest.java    From Strata with Apache License 2.0 5 votes vote down vote up
@Test
public void test_trade() {
  FraCurveNode node = FraCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD);
  LocalDate valuationDate = LocalDate.of(2015, 1, 22);
  double rate = 0.035;
  ImmutableMarketData marketData = ImmutableMarketData.builder(valuationDate).addValue(QUOTE_ID, rate).build();
  FraTrade trade = node.trade(1d, marketData, REF_DATA);
  LocalDate startDateExpected =
      BDA_MOD_FOLLOW.adjust(OFFSET.adjust(valuationDate, REF_DATA).plus(PERIOD_TO_START), REF_DATA);
  LocalDate endDateExpected =
      BDA_MOD_FOLLOW.adjust(OFFSET.adjust(valuationDate, REF_DATA).plus(PERIOD_TO_END), REF_DATA);
  Fra productExpected = Fra.builder()
      .buySell(BuySell.SELL)
      .currency(GBP)
      .dayCount(ACT_365F)
      .startDate(startDateExpected)
      .endDate(endDateExpected)
      .paymentDate(AdjustableDate.of(startDateExpected))
      .notional(1.0d)
      .index(GBP_LIBOR_3M)
      .fixedRate(rate + SPREAD)
      .build();
  TradeInfo tradeInfoExpected = TradeInfo.builder()
      .tradeDate(valuationDate)
      .build();
  assertThat(trade.getProduct()).isEqualTo(productExpected);
  assertThat(trade.getInfo()).isEqualTo(tradeInfoExpected);
}
 
Example 10
Source File: OvernightIborSwapCurveNodeTest.java    From Strata with Apache License 2.0 5 votes vote down vote up
@Test
public void test_metadata_fixed() {
  OvernightIborSwapCurveNode node =
      OvernightIborSwapCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD, LABEL).withDate(CurveNodeDate.of(VAL_DATE));
  LocalDate valuationDate = LocalDate.of(2015, 1, 22);
  DatedParameterMetadata metadata = node.metadata(valuationDate, REF_DATA);
  assertThat(metadata.getDate()).isEqualTo(VAL_DATE);
  assertThat(metadata.getLabel()).isEqualTo(node.getLabel());
}
 
Example 11
Source File: DiscountingCapitalIndexedBondProductPricerTest.java    From Strata with Apache License 2.0 5 votes vote down vote up
@Test
public void test_cleanNominalPrice_dirtyNominalPrice() {
  double dirtyNominalPrice = 1.055;
  LocalDate refDate = LocalDate.of(2014, 6, 10);
  double cleanNominalPrice =
      PRICER.cleanNominalPriceFromDirtyNominalPrice(PRODUCT, RATES_PROVIDER, refDate, dirtyNominalPrice);
  RateComputation obs = RATE_CALC.createRateComputation(VALUATION);
  double refRate = RateComputationFn.standard().rate(obs, null, null, RATES_PROVIDER);
  double expected = dirtyNominalPrice - PRODUCT.accruedInterest(refDate) * (refRate + 1d) / NOTIONAL;
  assertThat(cleanNominalPrice).isCloseTo(expected, offset(TOL));
  assertThat(PRICER.dirtyNominalPriceFromCleanNominalPrice(PRODUCT, RATES_PROVIDER, refDate, cleanNominalPrice)).isCloseTo(dirtyNominalPrice, offset(TOL));
}
 
Example 12
Source File: DayCountTest.java    From Strata with Apache License 2.0 5 votes vote down vote up
@Test
public void test_actAct_isdaTestCase_shortFinalStub() {
  LocalDate start = LocalDate.of(1999, 7, 30);
  LocalDate lastRegular = LocalDate.of(2000, 1, 30);
  LocalDate end = LocalDate.of(2000, 6, 30);
  ScheduleInfo info1 = new Info(start, end, lastRegular, true, P6M);  // regular period
  ScheduleInfo info2 = new Info(start, end, end, true, P6M);  // final period
  assertThat(ACT_ACT_ISDA.yearFraction(start, lastRegular)).isEqualTo((155d / 365d) + (29d / 366d));
  assertThat(ACT_ACT_ICMA.yearFraction(start, lastRegular, info1)).isEqualTo((184d / (184d * 2d)));
  assertThat(ACT_ACT_AFB.yearFraction(start, lastRegular)).isEqualTo((184d / 365d));

  assertThat(ACT_ACT_ISDA.yearFraction(lastRegular, end)).isEqualTo((152d / 366d));
  assertThat(ACT_ACT_ICMA.yearFraction(lastRegular, end, info2)).isEqualTo((152d / (182d * 2d)));
  assertThat(ACT_ACT_AFB.yearFraction(lastRegular, end)).isEqualTo((152d / 366d));
}
 
Example 13
Source File: TCKYear.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_atDay_leapYear() {
    Year test = Year.of(2008);
    LocalDate expected = LocalDate.of(2008, 1, 1);
    for (int i = 1; i <= 366; i++) {
        assertEquals(test.atDay(i), expected);
        expected = expected.plusDays(1);
    }
}
 
Example 14
Source File: IborFutureCurveNodeTest.java    From Strata with Apache License 2.0 5 votes vote down vote up
@Test
public void test_metadata_end() {
  IborFutureCurveNode node = IborFutureCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD, LABEL);
  LocalDate date = LocalDate.of(2015, 10, 20);
  LocalDate referenceDate = TEMPLATE.calculateReferenceDateFromTradeDate(date, REF_DATA);
  LocalDate maturityDate = TEMPLATE.getIndex().calculateMaturityFromEffective(referenceDate, REF_DATA);
  ParameterMetadata metadata = node.metadata(date, REF_DATA);
  assertThat(metadata.getLabel()).isEqualTo(LABEL);
  assertThat(metadata instanceof YearMonthDateParameterMetadata).isTrue();
  assertThat(((YearMonthDateParameterMetadata) metadata).getDate()).isEqualTo(maturityDate);
  assertThat(((YearMonthDateParameterMetadata) metadata).getYearMonth()).isEqualTo(YearMonth.from(referenceDate));
}
 
Example 15
Source File: TCKLocalDate.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void factory_ofYearDay_ints_nonLeap() {
    LocalDate date = LocalDate.of(2007, 1, 1);
    for (int i = 1; i < 365; i++) {
        assertEquals(LocalDate.ofYearDay(2007, i), date);
        date = next(date);
    }
}
 
Example 16
Source File: ArgCheckerTest.java    From Strata with Apache License 2.0 5 votes vote down vote up
@Test
public void test_inOrderNotEqual_false_equal() {
  LocalDate a = LocalDate.of(2011, 7, 3);
  assertThatIllegalArgumentException()
      .isThrownBy(() -> ArgChecker.inOrderNotEqual(a, a, "a", "b"))
      .withMessageMatching(".*a.* [<] .*b.*");
}
 
Example 17
Source File: TCKDateTimeFormatters.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_parse_weekDate() {
    LocalDate expected = LocalDate.of(2004, 1, 28);
    assertEquals(DateTimeFormatter.ISO_WEEK_DATE.parse("2004-W05-3", LocalDate::from), expected);
}
 
Example 18
Source File: TCKLocalDate.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_atTime_OffsetTime() {
    LocalDate t = LocalDate.of(2008, 6, 30);
    assertEquals(t.atTime(OffsetTime.of(11, 30, 0, 0, OFFSET_PONE)), OffsetDateTime.of(2008, 6, 30, 11, 30, 0, 0, OFFSET_PONE));
}
 
Example 19
Source File: TCKYearMonth.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_adjustDate_resolve() {
    YearMonth test = YearMonth.of(2007, 2);
    LocalDate date = LocalDate.of(2008, 3, 31);
    assertEquals(test.adjustInto(date), LocalDate.of(2007, 2, 28));
}
 
Example 20
Source File: MarketDayQuery.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void check_if_random_date_is_market_day() {
	
	LocalDate date = LocalDate.of(2014, 02, 02); // Sunday

	Boolean marketDay = date.query(new MarketDayQuery());

	assertTrue(marketDay);
}