private List<ReportEntry> fillForEmptyPeriods(
      List<ReportEntry> inputEntries, Pair<LocalDate, LocalDate> interval) {
    Optional<String> aRosterTypeCode =
        inputEntries.stream().map(ReportEntry::getRosterTypeCode).findAny();

    if (!aRosterTypeCode.isPresent()) {
      return inputEntries;
    }
    List<ReportEntry> result = inputEntries.stream().collect(Collectors.toList());

    for (LocalDate period = interval.getLeft();
        period.isBefore(interval.getRight());
        period = period.plusMonths(1)) {
      result.add(
          new ReportEntry(
              beneficiary,
              aRosterTypeCode.get(),
              AmountType.PAYMENT,
              YearMonth.from(period),
              BigDecimal.ZERO));
      result.add(
          new ReportEntry(
              beneficiary, "UNKNOWN", AmountType.REFUND, YearMonth.from(period), BigDecimal.ZERO));
    }
    return result;
  }
  public List<User> findUsers(final LocalDate startDate, final LocalDate endDate) {
    Predicate<User> filterPredicate =
        user -> {
          final LocalDate dateOfBirth = user.getDateOfBirth();
          return !dateOfBirth.isBefore(startDate) && !dateOfBirth.isAfter(endDate);
        };

    return users.stream().filter(filterPredicate).collect(Collectors.toList());
  }
Example #3
0
  /**
   * Checks if the allocation is currently active
   *
   * @return A status representing the active time state of the allocation
   */
  public AllocationStatus getTimeState() {
    LocalDate now = LocalDate.now();

    if (this.getEndDate() != null) {
      if (now.isAfter(this.getEndDate())) {
        return AllocationStatus.PAST; // Is a past allocation
      }
      if (!now.isBefore(this.getStartDate()) && !now.isAfter(this.getEndDate())) {
        return AllocationStatus.CURRENT; // Is a current allocation
      }
    }

    if (!now.isBefore(this.getStartDate())) {
      return AllocationStatus.CURRENT; // Is a current allocation
    } else {
      return AllocationStatus.FUTURE; // Is a future allocation
    }
  }
Example #4
0
 /**
  * Gets the relative year fraction between the specified dates.
  *
  * <p>Given two dates, this method returns the fraction of a year between these dates according to
  * the convention. The result of this method will be negative if the first date is after the
  * second date. The result is calculated using {@link #yearFraction(LocalDate, LocalDate,
  * ScheduleInfo)}.
  *
  * @param firstDate the first date
  * @param secondDate the second date, which may be before the first date
  * @param scheduleInfo the schedule information
  * @return the year fraction, may be negative
  * @throws UnsupportedOperationException if the year fraction cannot be obtained
  */
 public default double relativeYearFraction(
     LocalDate firstDate, LocalDate secondDate, ScheduleInfo scheduleInfo) {
   ArgChecker.notNull(firstDate, "firstDate");
   ArgChecker.notNull(secondDate, "secondDate");
   ArgChecker.notNull(scheduleInfo, "scheduleInfo");
   if (secondDate.isBefore(firstDate)) {
     return -yearFraction(secondDate, firstDate, scheduleInfo);
   }
   return yearFraction(firstDate, secondDate, scheduleInfo);
 }
  public static List<Descriptor> getDescriptors(
      @NotNull ReportPeriod reportPeriod,
      @NotNull LocalDate startDate,
      @NotNull LocalDate endDate) {

    final List<Descriptor> descriptors = new ArrayList<>();

    LocalDate start = startDate;
    LocalDate end = startDate;

    switch (reportPeriod) {
      case YEARLY:
        while (end.isBefore(endDate)) {
          end = end.with(TemporalAdjusters.lastDayOfYear());
          descriptors.add(new Descriptor(start, end, "    " + start.getYear()));
          start = end.plusDays(1);
        }
        break;
      case QUARTERLY:
        int i = DateUtils.getQuarterNumber(start) - 1;
        while (end.isBefore(endDate)) {
          end = DateUtils.getLastDayOfTheQuarter(start);
          descriptors.add(new Descriptor(start, end, " " + start.getYear() + "-Q" + (1 + i++ % 4)));
          start = end.plusDays(1);
        }
        break;
      case MONTHLY:
        while (end.isBefore(endDate)) {
          end = DateUtils.getLastDayOfTheMonth(start);
          final int month = start.getMonthValue();
          descriptors.add(
              new Descriptor(
                  start, end, " " + start.getYear() + (month < 10 ? "/0" + month : "/" + month)));
          start = end.plusDays(1);
        }
        break;
      default:
    }

    return descriptors;
  }
Example #6
0
  /**
   * A forward starting CDS starts on some date after today (the trade date). The accrual start must
   * be specified (would normally use this for T+1 accrual atart). The stepin date and cash
   * settlement date are taken from the forward start date (1 day and 3 working days by default).
   *
   * @param tradeDate the trade date (i.e. today)
   * @param forwardStartDate the forward start date
   * @param accStartDate the accrual start date
   * @param maturity the maturity of the CDS
   * @return a CDS analytic description for a forward starting CDS
   */
  public CdsAnalytic makeForwardStartingCds(
      LocalDate tradeDate, LocalDate forwardStartDate, LocalDate accStartDate, LocalDate maturity) {

    ArgChecker.isFalse(
        forwardStartDate.isBefore(tradeDate),
        "forwardStartDate of {} is before trade date of {}",
        forwardStartDate,
        tradeDate);
    LocalDate stepinDate = forwardStartDate.plusDays(_stepIn);
    LocalDate valueDate = addWorkDays(forwardStartDate, _cashSettle, _calendar);
    return makeCds(tradeDate, stepinDate, valueDate, accStartDate, maturity);
  }
Example #7
0
 /**
  * A forward starting CDS starts on some date after today (the trade date). The stepin date and
  * cash settlement date are taken from the forward start date (1 day and 3 working days by
  * default).
  *
  * @param tradeDate the trade date (i.e. today)
  * @param forwardStartDate the forward start date
  * @param maturity the maturity of the CDS
  * @return a CDS analytic description for a forward starting CDS
  */
 public CdsAnalytic makeForwardStartingCds(
     LocalDate tradeDate, LocalDate forwardStartDate, LocalDate maturity) {
   ArgChecker.isFalse(
       forwardStartDate.isBefore(tradeDate),
       "forwardStartDate of {} is before trade date of {}",
       forwardStartDate,
       tradeDate);
   LocalDate stepinDate = forwardStartDate.plusDays(_stepIn);
   LocalDate valueDate = addWorkDays(forwardStartDate, _cashSettle, _calendar);
   LocalDate accStartDate =
       _businessdayAdjustmentConvention.adjust(
           ImmDateLogic.getPrevIMMDate(forwardStartDate), _calendar);
   return makeCds(tradeDate, stepinDate, valueDate, accStartDate, maturity);
 }
Example #8
0
  @Test
  public void testThatPerformanceOfAnInvestmentIntoAnIndexIsIdenticalToIndex() {
    LocalDate startDate = LocalDate.of(2012, 1, 1);
    LocalDate endDate = LocalDate.of(2012, 4, 29); // a weekend
    long startPrice = Values.Quote.factorize(100);

    Client client = new Client();

    Security security =
        new SecurityBuilder() //
            .generatePrices(startPrice, startDate, endDate) //
            .addTo(client);

    PortfolioBuilder portfolio = new PortfolioBuilder(new Account());

    // add some buy transactions
    LocalDate date = startDate;
    while (date.isBefore(endDate)) {
      long p = security.getSecurityPrice(date).getValue();
      portfolio.inbound_delivery(security, date, Values.Share.factorize(100), p);
      date = date.plusDays(20);
    }

    portfolio.addTo(client);

    ReportingPeriod.FromXtoY period = new ReportingPeriod.FromXtoY(startDate, endDate);

    List<Exception> warnings = new ArrayList<Exception>();
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientIndex index = PerformanceIndex.forClient(client, converter, period, warnings);
    assertTrue(warnings.isEmpty());

    double[] accumulated = index.getAccumulatedPercentage();
    long lastPrice = security.getSecurityPrice(endDate).getValue();

    assertThat(
        (double) (lastPrice - startPrice) / (double) startPrice,
        IsCloseTo.closeTo(accumulated[accumulated.length - 1], PRECISION));

    PerformanceIndex benchmark = PerformanceIndex.forSecurity(index, security);
    assertThat(
        benchmark.getFinalAccumulatedPercentage(), is(index.getFinalAccumulatedPercentage()));
  }
 /**
  * Checks if this range is entirely before the specified time.
  *
  * <p>The comparison is based on the time-line position of the time within a day.
  *
  * @param other the other time to compare to, not null
  * @return true if this range is entirely before the specified time
  * @throws NullPointerException if {@code other} is null
  */
 public boolean isBefore(LocalDate other) {
   return endDate.isBefore(other);
 }
 protected static void testAssumptions(
     LocalDate reference, LocalDate dateBefore, LocalDate dateAfter) {
   assumeTrue(dateBefore.isBefore(reference));
   assumeTrue(dateAfter.isAfter(reference));
 }
Example #11
0
  /**
   * Gets new order parameters and rewrites it with new ones
   *
   * @param request
   * @param response
   * @throws ServletException
   * @throws IOException
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    User user = (User) request.getSession().getAttribute("user");
    int userId = user.getUserId();

    int orderId = (int) request.getSession().getAttribute("order_id");
    String act = request.getParameter("actionName");
    if (null != request.getParameter("actionName")) {
      if (act.equals("submit_edit")) {
        int places = Integer.parseInt(request.getParameter("places"));
        int classOfComfort = Integer.parseInt(request.getParameter("class"));
        String comment = request.getParameter("comment");
        DateTimeFormatter formatter =
            DateTimeFormatter.ofPattern(OrderFormServlet.FORMATTER_PATTERN);
        String date_in = request.getParameter("date_in");
        String date_out = request.getParameter("date_out");
        LocalDate dateIn = LocalDate.parse(date_in, formatter);
        LocalDate dateOut = LocalDate.parse(date_out, formatter);
        if (dateIn.isAfter(LocalDate.now()) && dateIn.isBefore(dateOut)) {
          try {
            int affectedRows =
                DBHandler.getInstance()
                    .editOrder(orderId, userId, places, classOfComfort, dateIn, dateOut, comment);
            if (affectedRows != 0) {
              response.sendRedirect(USER_JSP);
            } else {
              Locale locale = (Locale) request.getSession().getAttribute("locale");
              ResourceBundle resourceBundle = ResourceBundle.getBundle(PROPERTY, locale);
              String logErr = resourceBundle.getString("order.edit.result_error.log");
              request.setAttribute("error", true);
              LOG.error(logErr + " " + String.valueOf(affectedRows));
              fwd(request, response);
            }

          } catch (SQLException e) {
            e.printStackTrace();
            request.setAttribute("order_error", e.getMessage());
            LOG.error(e.getMessage());
            fwd(request, response);
          }
        } else {
          request.setAttribute("order_error", true);
          fwd(request, response);
        }
      } else {
        try {
          Order order = DBHandler.getInstance().getOrder(orderId);
          request.setAttribute("order", order);
        } catch (SQLException e) {
          e.printStackTrace();
          request.setAttribute("error", true);
          LOG.error(e.getMessage());
        }

        fwd(request, response);
      }

    } else {
      fwd(request, response);
    }
  }
 public boolean isOverdue() {
   if (hasBeenReturned) return false;
   if (dueDate.isBefore(LocalDate.now())) return true;
   return false;
 }
  @FilterWith(XSRFFilter.class)
  public Result dryRun(
      Context context, @Param("startDate") String start, @Param("endDate") String end) {
    long _start = System.currentTimeMillis();
    FlashScope flash = context.getFlashScope();

    LocalDate startDate = null;
    LocalDate endDate = null;

    try {
      startDate = LocalDate.parse(start);
      endDate = LocalDate.parse(end);
    } catch (Exception ex) {
    }

    if (startDate == null || endDate == null || startDate.isAfter(endDate)) {
      flash.error("error.invalidDate");
      return Results.redirect(router.getReverseRoute(DebugController.class, "debug"));
    }

    Run lastRun = baseDB.run.findLast(Module.GOOGLE, null, null);
    if (lastRun != null && lastRun.getDay().isAfter(startDate)) {
      flash.error("error.invalidDate");
      return Results.redirect(router.getReverseRoute(DebugController.class, "debug"));
    }

    LocalDate date = LocalDate.from(startDate);

    GoogleSettings ggOptions = googleDB.options.get();

    int minPauseBetweenPageSec = ggOptions.getMinPauseBetweenPageSec();
    int maxPauseBetweenPageSec = ggOptions.getMaxPauseBetweenPageSec();
    ggOptions.setMinPauseBetweenPageSec(0);
    ggOptions.setMaxPauseBetweenPageSec(0);
    googleDB.options.update(ggOptions);

    try {
      while (date.isBefore(endDate)) {
        LOG.debug("dry run {}", date);
        if (!taskManager.startGoogleTask(
            new Run(Run.Mode.MANUAL, Module.GOOGLE, date.atTime(13, 37, 00)))) {
          LOG.error("can't startGoogleTask");
          flash.error("can't startGoogleTask");
          return Results.redirect(router.getReverseRoute(DebugController.class, "debug"));
        }
        taskManager.joinGoogleTask();
        date = date.plusDays(1);
      }
    } catch (Exception ex) {
      LOG.error("an error occured", ex);
      flash.error("an error occured");
      return Results.redirect(router.getReverseRoute(DebugController.class, "debug"));
    } finally {
      ggOptions.setMinPauseBetweenPageSec(minPauseBetweenPageSec);
      ggOptions.setMaxPauseBetweenPageSec(maxPauseBetweenPageSec);
      googleDB.options.update(ggOptions);
    }

    LOG.debug(
        "dry run timing : {}",
        DurationFormatUtils.formatDurationHMS(System.currentTimeMillis() - _start));
    flash.success("ok");
    return Results.redirect(router.getReverseRoute(DebugController.class, "debug"));
  }
Example #14
0
 public static boolean shouldRecordError(LocalDate localDate, String eMessage) {
   if (isWeekDay(localDate) && localDate.isBefore(LocalDate.now())) {
     return true;
   }
   return false;
 }
 @Override
 boolean filter(LocalDate itemDate, LocalDate thresholdDate) {
   return itemDate.isBefore(thresholdDate);
 }