gpt4 book ai didi

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

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

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

YearMonth.isBefore介绍

[英]Is this year-month before the specified year-month.
[中]是指定年份月份之前的本年月份。

代码示例

代码示例来源:origin: stackoverflow.com

List<LocalDate> tooEarly = new ArrayList<>();
List<LocalDate> tooLate = new ArrayList<>();
List<LocalDate> justRight = new ArrayList<>();

for (String date : dates) {
  YearMonth ym = YearMonth.from( date );
  if( ym.isBefore( start ) ) {
    tooEarly.add( date );
  } else if( ! ym.isBefore( stop ) ) {  // Using Half-Open approach where ending is *exclusive*. Use “( ym.isAfter( stop ) )” if you want inclusive ending.
    tooLate.add( date );
  } else {
    justRight.add( date );
  }
  System.out.println( "ERROR unexpectedly went beyond the if-else-else." ); 
}

代码示例来源:origin: stackoverflow.com

YearMonth yearMonth = start ;
while ( yearMonth.isBefore( stop ) ) {
  yearMonths.add( yearMonth ) ;  // Add each incremented YearMonth to our collection.
  // Set up next loop.
  yearMonth.addMonths( 1 );
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) {        
  DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM-yyyy", Locale.ENGLISH);
  YearMonth startDate = YearMonth.parse("Jan-2015", formatter);
  YearMonth endDate = YearMonth.parse("Apr-2015", formatter);

  while(startDate.isBefore(endDate)) {
    System.out.println(startDate.format(formatter));
    startDate = startDate.plusMonths(1);
  }
}

代码示例来源:origin: stackoverflow.com

YearMonth ym = ymStart;
do {
  int daysInMonth = ym.lengthOfMonth ();
  String monthName = ym.getMonth ().getDisplayName ( TextStyle.FULL , Locale.CANADA_FRENCH );

  System.out.println ( ym + " : " + daysInMonth + " jours en " + monthName );

  // Prepare for next loop.
  ym = ym.plusMonths ( 1 );
} while ( ym.isBefore ( ymStop ) );

代码示例来源:origin: br.com.jarch/jarch-util

public static Collection<YearMonth> generateFromLocalDate(LocalDate start, LocalDate end) {
    YearMonth yearMonthActual = YearMonth.of(start.getYear(), start.getMonth());
    YearMonth yearMonthEnd = YearMonth.of(end.getYear(), end.getMonth());

    List<YearMonth> listYearMonthReturn = new ArrayList<>();
    do {
      listYearMonthReturn.add(yearMonthActual);
      yearMonthActual = yearMonthActual.plusMonths(1);
    } while (yearMonthActual.isBefore(yearMonthEnd));

    listYearMonthReturn.add(yearMonthEnd);

    return listYearMonthReturn;
  }
}

代码示例来源:origin: br.com.jarch/jarch-utils

public static Collection<YearMonth> generateFromLocalDate(LocalDate start, LocalDate end) {
    YearMonth yearMonthActual = YearMonth.of(start.getYear(), start.getMonth());
    YearMonth yearMonthEnd = YearMonth.of(end.getYear(), end.getMonth());

    List<YearMonth> listYearMonthReturn = new ArrayList<>();
    do {
      listYearMonthReturn.add(yearMonthActual);
      yearMonthActual = yearMonthActual.plusMonths(1);
    } while (yearMonthActual.isBefore(yearMonthEnd));

    listYearMonthReturn.add(yearMonthEnd);

    return listYearMonthReturn;
  }
}

代码示例来源: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: 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();
  }
 }
 // otherwise, return the estimate from the curve.
 double nbMonth = numberOfMonths(fixingMonth);
 return curve.yValue(nbMonth);
}

代码示例来源:origin: stackoverflow.com

YearMonth yearMonth = startYm;
do {
  int days = 0;
  if ( startYm.equals ( stopYm ) ) { // If within the same (single) month.
    days = ( int ) ChronoUnit.DAYS.between ( start , stop );
  } else if ( yearMonth.equals ( startYm ) ) { // If on the first month of multiple months, count days.
    days = ( int ) ChronoUnit.DAYS.between ( start , startYm.plusMonths ( 1 ).atDay ( 1 ) ); //  Get first of next month, to accommodate the `between` method’s use of Half-Open logic.
  } else if ( yearMonth.isAfter ( startYm ) && yearMonth.isBefore ( stopYm ) ) { // If on the in-between months, ask for the days of that month.
    days = yearMonth.lengthOfMonth ();
  } else if ( yearMonth.equals ( stopYm ) ) {  // If on the last of multiple months.
    days = ( int ) ChronoUnit.DAYS.between ( stopYm.atDay ( 1 ).minusDays ( 1 ) , stop ); // Get last day of previous month, to accommodate the `between` method’s use of Half-Open logic.
  } else {
    System.out.println ( "ERROR - Reached impossible point." );
    // FIXME: Handle error condition.
  }
  map.put ( yearMonth , days ); // Cast long to int, auto-boxed to Integer.
  // Prep for next loop.
  yearMonth = yearMonth.plusMonths ( 1 );
} while (  ! yearMonth.isAfter ( stopYm ) );

代码示例来源:origin: br.com.jarch/jarch-annotation

YearMonth dateBegin = (YearMonth) objectBegin;
YearMonth dateEnd = (YearMonth) objectEnd;
valid = dateBegin.isBefore(dateEnd);

代码示例来源: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

@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

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 test_value_futfixing() {
 for (int i = 0; i < TEST_MONTHS.length; i++) {
  double valueComputed = INSTANCE_WITH_FUTFIXING.value(TEST_OBS[i]);
  YearMonth fixingMonth = TEST_OBS[i].getFixingMonth();
  double valueExpected;
  if (fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) {
   valueExpected = USCPI_TS.get(fixingMonth.atEndOfMonth()).getAsDouble();
  } else {
   double x = YearMonth.from(VAL_DATE_2).until(fixingMonth, MONTHS);
   valueExpected = CURVE_INFL2.yValue(x);
  }
  assertEquals(valueComputed, valueExpected, TOLERANCE_VALUE, "test " + i);
 }
}

代码示例来源: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);
 }
}

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

public void test_value_parameter_sensitivity_futfixing() {
 for (int i = 0; i < TEST_MONTHS.length; i++) {
  YearMonth fixingMonth = TEST_OBS[i].getFixingMonth();
  if (!fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && !USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) {
   InflationRateSensitivity ptsExpected = (InflationRateSensitivity) InflationRateSensitivity.of(TEST_OBS[i], 1d);
   CurrencyParameterSensitivities psComputed = INSTANCE_WITH_FUTFIXING.parameterSensitivity(ptsExpected);
   double x = YearMonth.from(VAL_DATE_2).until(fixingMonth, MONTHS);
   UnitParameterSensitivities sens1 = UnitParameterSensitivities.of(CURVE_INFL2.yValueParameterSensitivity(x));
   CurrencyParameterSensitivities psExpected =
     sens1.multipliedBy(ptsExpected.getCurrency(), ptsExpected.getSensitivity());
   assertTrue(psComputed.equalWithTolerance(psExpected, TOLERANCE_DELTA), "test " + i);
  }
 }
}

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

ArgChecker.isTrue(lastMonth.isBefore(valuationMonth), "Last fixing month must be before valuation date");
double nbMonth = valuationMonth.until(lastMonth, MONTHS);
DoubleArray x = curveWithoutFixing.getXValues();

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