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

x33g5p2x  于2022-02-05 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(114)

本文整理了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

  1. List<LocalDate> tooEarly = new ArrayList<>();
  2. List<LocalDate> tooLate = new ArrayList<>();
  3. List<LocalDate> justRight = new ArrayList<>();
  4. for (String date : dates) {
  5. YearMonth ym = YearMonth.from( date );
  6. if( ym.isBefore( start ) ) {
  7. tooEarly.add( date );
  8. } else if( ! ym.isBefore( stop ) ) { // Using Half-Open approach where ending is *exclusive*. Use “( ym.isAfter( stop ) )” if you want inclusive ending.
  9. tooLate.add( date );
  10. } else {
  11. justRight.add( date );
  12. }
  13. System.out.println( "ERROR unexpectedly went beyond the if-else-else." );
  14. }

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

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

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

  1. public static void main(String[] args) {
  2. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM-yyyy", Locale.ENGLISH);
  3. YearMonth startDate = YearMonth.parse("Jan-2015", formatter);
  4. YearMonth endDate = YearMonth.parse("Apr-2015", formatter);
  5. while(startDate.isBefore(endDate)) {
  6. System.out.println(startDate.format(formatter));
  7. startDate = startDate.plusMonths(1);
  8. }
  9. }

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

  1. YearMonth ym = ymStart;
  2. do {
  3. int daysInMonth = ym.lengthOfMonth ();
  4. String monthName = ym.getMonth ().getDisplayName ( TextStyle.FULL , Locale.CANADA_FRENCH );
  5. System.out.println ( ym + " : " + daysInMonth + " jours en " + monthName );
  6. // Prepare for next loop.
  7. ym = ym.plusMonths ( 1 );
  8. } while ( ym.isBefore ( ymStop ) );

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

  1. public static Collection<YearMonth> generateFromLocalDate(LocalDate start, LocalDate end) {
  2. YearMonth yearMonthActual = YearMonth.of(start.getYear(), start.getMonth());
  3. YearMonth yearMonthEnd = YearMonth.of(end.getYear(), end.getMonth());
  4. List<YearMonth> listYearMonthReturn = new ArrayList<>();
  5. do {
  6. listYearMonthReturn.add(yearMonthActual);
  7. yearMonthActual = yearMonthActual.plusMonths(1);
  8. } while (yearMonthActual.isBefore(yearMonthEnd));
  9. listYearMonthReturn.add(yearMonthEnd);
  10. return listYearMonthReturn;
  11. }
  12. }

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

  1. public static Collection<YearMonth> generateFromLocalDate(LocalDate start, LocalDate end) {
  2. YearMonth yearMonthActual = YearMonth.of(start.getYear(), start.getMonth());
  3. YearMonth yearMonthEnd = YearMonth.of(end.getYear(), end.getMonth());
  4. List<YearMonth> listYearMonthReturn = new ArrayList<>();
  5. do {
  6. listYearMonthReturn.add(yearMonthActual);
  7. yearMonthActual = yearMonthActual.plusMonths(1);
  8. } while (yearMonthActual.isBefore(yearMonthEnd));
  9. listYearMonthReturn.add(yearMonthEnd);
  10. return listYearMonthReturn;
  11. }
  12. }

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

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

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

  1. @Override
  2. public double value(PriceIndexObservation observation) {
  3. YearMonth fixingMonth = observation.getFixingMonth();
  4. // If fixing in the past, check time series and returns the historic month price index if present
  5. if (fixingMonth.isBefore(YearMonth.from(valuationDate))) {
  6. OptionalDouble fixing = fixings.get(fixingMonth.atEndOfMonth());
  7. if (fixing.isPresent()) {
  8. return fixing.getAsDouble();
  9. }
  10. }
  11. // otherwise, return the estimate from the curve.
  12. double nbMonth = numberOfMonths(fixingMonth);
  13. return curve.yValue(nbMonth);
  14. }

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

  1. YearMonth yearMonth = startYm;
  2. do {
  3. int days = 0;
  4. if ( startYm.equals ( stopYm ) ) { // If within the same (single) month.
  5. days = ( int ) ChronoUnit.DAYS.between ( start , stop );
  6. } else if ( yearMonth.equals ( startYm ) ) { // If on the first month of multiple months, count days.
  7. 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.
  8. } else if ( yearMonth.isAfter ( startYm ) && yearMonth.isBefore ( stopYm ) ) { // If on the in-between months, ask for the days of that month.
  9. days = yearMonth.lengthOfMonth ();
  10. } else if ( yearMonth.equals ( stopYm ) ) { // If on the last of multiple months.
  11. 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.
  12. } else {
  13. System.out.println ( "ERROR - Reached impossible point." );
  14. // FIXME: Handle error condition.
  15. }
  16. map.put ( yearMonth , days ); // Cast long to int, auto-boxed to Integer.
  17. // Prep for next loop.
  18. yearMonth = yearMonth.plusMonths ( 1 );
  19. } while ( ! yearMonth.isAfter ( stopYm ) );

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

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

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

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

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

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

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

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

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

  1. public void test_value_futfixing() {
  2. for (int i = 0; i < TEST_MONTHS.length; i++) {
  3. double valueComputed = INSTANCE_WITH_FUTFIXING.value(TEST_OBS[i]);
  4. YearMonth fixingMonth = TEST_OBS[i].getFixingMonth();
  5. double valueExpected;
  6. if (fixingMonth.isBefore(YearMonth.from(VAL_DATE_2)) && USCPI_TS.containsDate(fixingMonth.atEndOfMonth())) {
  7. valueExpected = USCPI_TS.get(fixingMonth.atEndOfMonth()).getAsDouble();
  8. } else {
  9. double x = YearMonth.from(VAL_DATE_2).until(fixingMonth, MONTHS);
  10. valueExpected = CURVE_INFL2.yValue(x);
  11. }
  12. assertEquals(valueComputed, valueExpected, TOLERANCE_VALUE, "test " + i);
  13. }
  14. }

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

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

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

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

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

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

相关文章