gpt4 book ai didi

java.time.YearMonth.from()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-18 00:50:40 26 4
gpt4 key购买 nike

本文整理了Java中java.time.YearMonth.from()方法的一些代码示例,展示了YearMonth.from()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YearMonth.from()方法的具体详情如下:
包路径:java.time.YearMonth
类名称:YearMonth
方法名:from

YearMonth.from介绍

[英]Obtains an instance of YearMonth from a temporal object.

A TemporalAccessor represents some form of date and time information. This factory converts the arbitrary temporal object to an instance of YearMonth.

The conversion extracts the ChronoField#YEAR and ChronoField#MONTH_OF_YEAR fields. The extraction is only permitted if the temporal object has an ISO chronology, or can be converted to a LocalDate.

This method matches the signature of the functional interface TemporalQueryallowing it to be used in queries via method reference, YearMonth::from.
[中]从时间对象获取YearMonth的实例。
临时助理代表某种形式的日期和时间信息。该工厂将任意时态对象转换为YearMonth的实例。
转换将提取ChronoField#YEAR和ChronoField#MONTH_OF_YEAR字段。仅当时态对象具有ISO年表或可以转换为LocalDate时,才允许提取。
此方法匹配函数接口TemporalQueryLow的签名,通过方法引用YearMonth::from将其用于查询。

代码示例

代码示例来源:origin: jfoenixadmin/JFoenix

void clearFocus() {
  LocalDate focusDate = datePicker.getValue();
  if (focusDate == null) {
    focusDate = LocalDate.now();
  }
  if (YearMonth.from(focusDate).equals(selectedYearMonth.get())) {
    goToDate(focusDate, true);
  }
}

代码示例来源:origin: jfoenixadmin/JFoenix

private void goToDate(LocalDate date, boolean focusDayCell) {
  if (isValidDate(datePicker.getChronology(), date)) {
    selectedYearMonth.set(YearMonth.from(date));
    if (focusDayCell) {
      findDayCellOfDate(date).requestFocus();
    }
  }
}

代码示例来源:origin: jfoenixadmin/JFoenix

YearMonth.from(date) : YearMonth.now());
  content.updateValues();
LocalDate date = jfxDatePicker.getValue();
content.displayedYearMonthProperty().set((date != null) ?
  YearMonth.from(date) : YearMonth.now());
content.updateValues();

代码示例来源:origin: jfoenixadmin/JFoenix

selectedYearMonth.set((date != null) ? YearMonth.from(date) : YearMonth.now());
selectedYearMonth.addListener((observable, oldValue, newValue) -> updateValues());

代码示例来源:origin: com.github.seratch/java-time-backport

@Override
  public YearMonth queryFrom(TemporalAccessor temporal) {
    return YearMonth.from(temporal);
  }
};

代码示例来源:origin: OpenGamma/Strata

@Override
public DatedParameterMetadata metadata(LocalDate valuationDate, ReferenceData refData) {
 LocalDate nodeDate = date(valuationDate, refData);
 LocalDate referenceDate = template.calculateReferenceDateFromTradeDate(valuationDate, refData);
 if (label.isEmpty()) {
  return YearMonthDateParameterMetadata.of(nodeDate, YearMonth.from(referenceDate));
 }
 return YearMonthDateParameterMetadata.of(nodeDate, YearMonth.from(referenceDate), label);
}

代码示例来源:origin: vladmihalcea/high-performance-java-persistence

@Override
  public YearMonth convertToEntityAttribute(java.sql.Date dbData) {
    return YearMonth.from(Instant.ofEpochMilli(dbData.getTime())
        .atZone(ZoneId.systemDefault())
        .toLocalDate());
  }
}

代码示例来源:origin: com.jfoenix/jfoenix

void clearFocus() {
  LocalDate focusDate = datePicker.getValue();
  if (focusDate == null) {
    focusDate = LocalDate.now();
  }
  if (YearMonth.from(focusDate).equals(selectedYearMonth.get())) {
    goToDate(focusDate, true);
  }
}

代码示例来源:origin: OpenGamma/Strata

@Override
public double value(PriceIndexObservation observation) {
 YearMonth fixingMonth = observation.getFixingMonth();
 // If fixing in the past, check time series and returns the historic month price index if present
 if (fixingMonth.isBefore(YearMonth.from(valuationDate))) {
  OptionalDouble fixing = fixings.get(fixingMonth.atEndOfMonth());
  if (fixing.isPresent()) {
   return fixing.getAsDouble();
  }
 }
 throw new MarketDataNotFoundException("Unable to query forward value for historic index " + index);
}

代码示例来源:origin: com.jfoenix/jfoenix

private void goToDate(LocalDate date, boolean focusDayCell) {
  if (isValidDate(datePicker.getChronology(), date)) {
    selectedYearMonth.set(YearMonth.from(date));
    if (focusDayCell) {
      findDayCellOfDate(date).requestFocus();
    }
  }
}

代码示例来源:origin: OpenGamma/Strata

@Test(dataProvider = "quarterly10th")
public void test_nextOrSameQuarterly10th(LocalDate base, LocalDate expect1, LocalDate expect2, LocalDate expect3) {
 LocalDate date = base.plusDays(1);
 while (!date.isAfter(expect1)) {
  assertEquals(DateSequences.QUARTERLY_10TH.nextOrSame(date), expect1);
  assertEquals(DateSequences.QUARTERLY_10TH.nthOrSame(date, 1), expect1);
  assertEquals(DateSequences.QUARTERLY_10TH.nthOrSame(date, 2), expect2);
  assertEquals(DateSequences.QUARTERLY_10TH.nthOrSame(date, 3), expect3);
  date = date.plusDays(1);
 }
 assertEquals(DateSequences.QUARTERLY_10TH.dateMatching(YearMonth.from(date)), expect1);
}

代码示例来源:origin: OpenGamma/Strata

@Test(dataProvider = "monthlyImm")
public void test_nextOrSameMonthlyImm(LocalDate base, LocalDate immDate1, LocalDate immDate2, LocalDate immDate3) {
 LocalDate date = base.plusDays(1);
 while (!date.isAfter(immDate1)) {
  assertEquals(DateSequences.MONTHLY_IMM.nextOrSame(date), immDate1);
  assertEquals(DateSequences.MONTHLY_IMM.nthOrSame(date, 1), immDate1);
  assertEquals(DateSequences.MONTHLY_IMM.nthOrSame(date, 2), immDate2);
  assertEquals(DateSequences.MONTHLY_IMM.nthOrSame(date, 3), immDate3);
  date = date.plusDays(1);
 }
 assertEquals(DateSequences.MONTHLY_IMM.dateMatching(YearMonth.from(date)), immDate1);
}

代码示例来源:origin: OpenGamma/Strata

@Test(dataProvider = "quarterlyImm")
public void test_nextOrSameQuarterlyImm(LocalDate base, LocalDate immDate1, LocalDate immDate2, LocalDate immDate3) {
 LocalDate date = base.plusDays(1);
 while (!date.isAfter(immDate1)) {
  assertEquals(DateSequences.QUARTERLY_IMM.nextOrSame(date), immDate1);
  assertEquals(DateSequences.QUARTERLY_IMM.nthOrSame(date, 1), immDate1);
  assertEquals(DateSequences.QUARTERLY_IMM.nthOrSame(date, 2), immDate2);
  assertEquals(DateSequences.QUARTERLY_IMM.nthOrSame(date, 3), immDate3);
  date = date.plusDays(1);
 }
 assertEquals(DateSequences.QUARTERLY_IMM.dateMatching(YearMonth.from(date)), immDate1);
}

代码示例来源:origin: OpenGamma/Strata

@Override
public PointSensitivityBuilder valuePointSensitivity(PriceIndexObservation observation) {
 YearMonth fixingMonth = observation.getFixingMonth();
 // If fixing in the past, check time series and returns the historic month price index if present
 if (fixingMonth.isBefore(YearMonth.from(valuationDate))) {
  if (fixings.get(fixingMonth.atEndOfMonth()).isPresent()) {
   return PointSensitivityBuilder.none();
  }
 }
 throw new MarketDataNotFoundException("Unable to query forward value sensitivity for historic index " + index);
}

代码示例来源:origin: OpenGamma/Strata

@Override
public PointSensitivityBuilder valuePointSensitivity(PriceIndexObservation observation) {
 YearMonth fixingMonth = observation.getFixingMonth();
 // If fixing in the past, check time series and returns the historic month price index if present
 if (fixingMonth.isBefore(YearMonth.from(valuationDate))) {
  if (fixings.get(fixingMonth.atEndOfMonth()).isPresent()) {
   return PointSensitivityBuilder.none();
  }
 }
 return InflationRateSensitivity.of(observation, 1d);
}

代码示例来源:origin: OpenGamma/Strata

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);
 assertEquals(metadata.getLabel(), LABEL);
 assertTrue(metadata instanceof YearMonthDateParameterMetadata);
 assertEquals(((YearMonthDateParameterMetadata) metadata).getDate(), maturityDate);
 assertEquals(((YearMonthDateParameterMetadata) metadata).getYearMonth(), YearMonth.from(referenceDate));
}

代码示例来源:origin: OpenGamma/Strata

private UnitParameterSensitivities unitParameterSensitivity(YearMonth month) {
 // If fixing in the past, check time series and returns the historic month price index if present
 if (month.isBefore(YearMonth.from(valuationDate))) {
  if (fixings.get(month.atEndOfMonth()).isPresent()) {
   return UnitParameterSensitivities.empty();
  }
 }
 double nbMonth = numberOfMonths(month);
 return UnitParameterSensitivities.of(curve.yValueParameterSensitivity(nbMonth));
}

代码示例来源:origin: OpenGamma/Strata

public void value_multiplicative() {
 InflationNodalCurve curveComputed = InflationNodalCurve.of(CURVE_NOFIX, VAL_DATE_2, LAST_FIX_MONTH_2, LAST_FIX_VALUE,
   SEASONALITY_MULTIPLICATIVE_DEF);
 for (int i = 1; i < TEST_MONTHS.length; i++) {
  double nbMonths = YearMonth.from(VAL_DATE_2).until(TEST_MONTHS[i], MONTHS);
  double valueComputed = curveComputed.yValue(nbMonths);
  int x = (int) ((nbMonths + 12) % 12);
  double valueNoAdj = EXTENDED_CURVE_2.yValue(nbMonths);
  double adj = SEASONALITY_MULTIPLICATIVE_COMP_2.get(x);
  double valueExpected = valueNoAdj * adj;
  assertEquals(valueExpected, valueComputed, TOLERANCE_VALUE);
 }
}

代码示例来源:origin: OpenGamma/Strata

public void test_metadata_last_fixing() {
 IborFutureCurveNode node =
   IborFutureCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD, LABEL).withDate(CurveNodeDate.LAST_FIXING);
 ImmutableMarketData marketData = ImmutableMarketData.builder(VAL_DATE).addValue(QUOTE_ID, 0.0d).build();
 IborFutureTrade trade = node.trade(1d, marketData, REF_DATA);
 LocalDate fixingDate = trade.getProduct().getFixingDate();
 DatedParameterMetadata metadata = node.metadata(VAL_DATE, REF_DATA);
 assertEquals(metadata.getDate(), fixingDate);
 LocalDate referenceDate = TEMPLATE.calculateReferenceDateFromTradeDate(VAL_DATE, REF_DATA);
 assertEquals(((YearMonthDateParameterMetadata) metadata).getYearMonth(), YearMonth.from(referenceDate));
}

代码示例来源:origin: OpenGamma/Strata

public void test_value_pts_sensitivity_futfixing() {
 for (int i = 0; i < TEST_MONTHS.length; i++) {
  PointSensitivityBuilder ptsComputed = INSTANCE_WITH_FUTFIXING.valuePointSensitivity(TEST_OBS[i]);
  YearMonth fixingMonth = TEST_OBS[i].getFixingMonth();
  PointSensitivityBuilder ptsExpected;
  if (fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) {
   ptsExpected = PointSensitivityBuilder.none();
  } else {
   ptsExpected = InflationRateSensitivity.of(TEST_OBS[i], 1d);
  }
  assertTrue(ptsComputed.build().equalWithTolerance(ptsExpected.build(), TOLERANCE_VALUE), "test " + i);
 }
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com