// -------------------------------------------------------------------------
 @Override
 public double relativeTime(ZonedDateTime dateTime) {
   ArgChecker.notNull(dateTime, "dateTime");
   LocalDate valuationDate = valuationDateTime.toLocalDate();
   LocalDate date = dateTime.toLocalDate();
   return dayCount.relativeYearFraction(valuationDate, date);
 }
 @Test
 public void test2() {
   final ZonedDateTime startDate = DateUtils.getUTCDate(2000, 1, 1);
   final ZonedDateTime endDate = DateUtils.getUTCDate(2002, 2, 9);
   final int months = 25;
   final ZonedDateTime[] forward = CALCULATOR.getSchedule(startDate, endDate, false, true);
   assertEquals(forward.length, months);
   final ZonedDateTime firstDate = DateUtils.getUTCDate(2000, 1, 31);
   assertEquals(forward[0], firstDate);
   final ZonedDateTime lastDate = DateUtils.getUTCDate(2002, 1, 31);
   assertEquals(forward[months - 1], lastDate);
   ZonedDateTime d1;
   for (int i = 1; i < months; i++) {
     d1 = forward[i];
     if (d1.getYear() == forward[i - 1].getYear()) {
       assertEquals(d1.getMonthValue() - forward[i - 1].getMonthValue(), 1);
     } else {
       assertEquals(d1.getMonthValue() - forward[i - 1].getMonthValue(), -11);
     }
     assertEquals(d1.getDayOfMonth(), d1.toLocalDate().lengthOfMonth());
   }
   assertArrayEquals(CALCULATOR.getSchedule(startDate, endDate, true, false), forward);
   assertArrayEquals(CALCULATOR.getSchedule(startDate, endDate, true, true), forward);
   assertArrayEquals(CALCULATOR.getSchedule(startDate, endDate, false, false), forward);
   assertArrayEquals(CALCULATOR.getSchedule(startDate, endDate, false, true), forward);
   assertArrayEquals(CALCULATOR.getSchedule(startDate, endDate), forward);
 }
Ejemplo n.º 3
0
 private static LocalDate parse(final DateTimeFormatter formatter, final String value) {
   try {
     Instant epoch = Instant.ofEpochMilli(Long.parseLong(value));
     ZonedDateTime zonedDate =
         epoch.atZone(Optional.ofNullable(formatter.getZone()).orElse(ZoneId.systemDefault()));
     return zonedDate.toLocalDate();
   } catch (NumberFormatException ex) {
     return LocalDate.parse(value, formatter);
   }
 }
Ejemplo n.º 4
0
  private Optional<MeteoExtrasForecastDay> createLongTermForecastDay(
      ZonedDateTime dt, LongtermTimeSeries.LongtermTimeSerie serie) {
    if (!getIndexer().hasForecastsForDay(dt)) {
      return Optional.empty();
    }

    List<MeteoExtrasForecast> forecasts = new ArrayList<>();
    for (LongtermTimeSeries.FromTo fromTo : serie.getFromTos()) {
      getForecastForPeriod(dt.plusHours(fromTo.getFrom()), dt.plusHours(fromTo.getTo()))
          .ifPresent(forecasts::add);
    }
    return forecasts.size() > 0
        ? Optional.of(new MeteoExtrasForecastDay(dt.toLocalDate(), forecasts))
        : Optional.empty();
  }
 // -------------------------------------------------------------------------
 @Override
 public double relativeTime(ZonedDateTime zonedDateTime) {
   ArgChecker.notNull(zonedDateTime, "date");
   return dayCount.relativeYearFraction(
       valuationDateTime.toLocalDate(), zonedDateTime.toLocalDate());
 }
Ejemplo n.º 6
0
 public MeteoExtrasForecastDay createSimpleForcastForDay(ZonedDateTime dateTime) {
   ZonedDateTime dt = toZeroMSN(dateTime.withZoneSameInstant(METZONE));
   List<MeteoExtrasForecast> forecasts = new ArrayList<>();
   // findNearestForecast(dt.withHour(12)).ifPresent(forecasts::add);
   return new MeteoExtrasForecastDay(dt.toLocalDate(), forecasts);
 }