private LocalDate parseCalendarDate(File file) {
    try {
      String html = FileUtils.readFileToString(file);
      Document doc = Jsoup.parse(html);
      Element title = doc.select("div.center").get(0);
      String calTitle = title.text();

      Pattern calDatePattern =
          Pattern.compile(
              "STATE OF NEW YORK SENATE CALENDAR (?<date>\\w+, \\w+ \\d{1,2}, \\d{4}) .*");
      Matcher matcher = calDatePattern.matcher(calTitle);
      if (matcher.find()) {
        String dateString = capitalizeAllWords(matcher.group("date"));
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("EEEE, MMMM d, yyyy");
        return LocalDate.from(dtf.parse(dateString));
      }
    } catch (IOException e) {
      logger.info("Unable to parse supplemental cal date for file: " + file.getName(), e);
    }
    return null;
  }
  private void testPeriod() {
    out.printf("--------------------- Test Period ------------------------------\n");

    birthDays
        .entrySet()
        .stream()
        .map(
            e -> {
              // string to Time
              return Tuple.from(e.getKey(), stringToTime(e.getValue()));
            })
        .map(
            t -> {
              // Time to Period
              return Tuple.from(t._1, Period.between(LocalDate.from(t._2), LocalDate.now()));
            })
        .forEach(
            t -> {
              out.printf(
                  "%s was born %s years, %s months, %s days ago.\n",
                  t._1, t._2.getYears(), t._2.getMonths(), t._2.getDays());
            });
  }
/** @author Andrey */
public class CellAnalysisBox<T> extends TableCell<T, IlliquidMainSalesStatusBean> {

  public static <S extends Object>
      Callback<
              TableColumn<S, IlliquidMainSalesStatusBean>,
              TableCell<S, IlliquidMainSalesStatusBean>>
          forTableColumn(TableColumn<S, IlliquidMainSalesStatusBean> tc) {
    Callback<TableColumn<S, IlliquidMainSalesStatusBean>, TableCell<S, IlliquidMainSalesStatusBean>>
        callback =
            new Callback<
                TableColumn<S, IlliquidMainSalesStatusBean>,
                TableCell<S, IlliquidMainSalesStatusBean>>() {
              @Override
              public TableCell call(TableColumn<S, IlliquidMainSalesStatusBean> p) {
                return new CellAnalysisBox<>();
              }
            };
    return callback;
  }

  public CellAnalysisBox() {
    setAlignment(Pos.CENTER);
    // setContentDisplay(ContentDisplay.);
  }

  Image imEmpty = new Image(this.getClass().getResourceAsStream("/images/" + "arEmpty.png"));
  Image imRed = new Image(this.getClass().getResourceAsStream("/images/" + "arRed.png"));
  Image imYelow = new Image(this.getClass().getResourceAsStream("/images/" + "arYellow.png"));
  Image imGreen = new Image(this.getClass().getResourceAsStream("/images/" + "arGreen.png"));
  LocalDate now = LocalDate.now();
  LocalDate per30From = LocalDate.from(now).minusDays(30);
  LocalDate per60From = LocalDate.from(now).minusDays(60);
  LocalDate per90From = LocalDate.from(now).minusDays(90);
  Tooltip tooltip = new Tooltip();

  @Override
  protected void updateItem(IlliquidMainSalesStatusBean item, boolean empty) {
    super.updateItem(item, empty);
    if ((!isEmpty()) && (item != null)) {
      StringBuilder tooltext = new StringBuilder();
      HBox hb = new HBox();
      hb.setAlignment(Pos.CENTER);
      VBox vb = new VBox();
      vb.setAlignment(Pos.CENTER);

      double totalCount =
          item.getCountTvr() + item.getDays30sale() + item.getDays60sale() + item.getDays90sale();
      double proc30;
      double proc60;
      double proc90;
      if (totalCount > 0) {
        proc30 = item.getDays30sale() / totalCount;
        proc60 = item.getDays60sale() / totalCount;
        proc90 = item.getDays90sale() / totalCount;
      } else {
        proc30 = 1;
        proc60 = 1;
        proc90 = 1;
      }

      if (proc30 == 0) {
        hb.getChildren().add(new ImageView(imEmpty));
        vb.getChildren().add(new ImageView(imEmpty));
      } else if (proc30 < 0.10) {
        hb.getChildren().add(new ImageView(imRed));
        vb.getChildren().add(new ImageView(imRed));
      } else if (proc30 >= 0.10 && proc30 < 0.30) {
        hb.getChildren().add(new ImageView(imYelow));
        vb.getChildren().add(new ImageView(imYelow));
      } else if (proc30 >= 0.30) {
        hb.getChildren().add(new ImageView(imGreen));
        vb.getChildren().add(new ImageView(imGreen));
      }
      tooltext
          .append("1 міс. {")
          .append(DateConverters.getDateToStr(per30From))
          .append(" - ")
          .append(DateConverters.getDateToStr(now))
          .append("}:  ")
          .append(String.format("%.2f", proc30 * 100))
          .append("%\n");

      if (proc60 == 0) {
        hb.getChildren().add(new ImageView(imEmpty));
        vb.getChildren().add(new ImageView(imEmpty));
      } else if (proc60 < 0.10) {
        hb.getChildren().add(new ImageView(imRed));
        vb.getChildren().add(new ImageView(imRed));
      } else if (proc60 >= 0.10 && proc60 < 0.30) {
        hb.getChildren().add(new ImageView(imYelow));
        vb.getChildren().add(new ImageView(imYelow));
      } else if (proc60 >= 0.30) {
        hb.getChildren().add(new ImageView(imGreen));
        vb.getChildren().add(new ImageView(imGreen));
      }
      tooltext
          .append("2 міс. {")
          .append(DateConverters.getDateToStr(per60From))
          .append(" - ")
          .append(DateConverters.getDateToStr(per30From))
          .append("}:  ")
          .append(String.format("%.2f", proc60 * 100))
          .append("%\n");

      if (proc90 == 0) {
        hb.getChildren().add(new ImageView(imEmpty));
        vb.getChildren().add(new ImageView(imEmpty));
      } else if (proc90 < 0.10) {
        hb.getChildren().add(new ImageView(imRed));
        vb.getChildren().add(new ImageView(imRed));
      } else if (proc90 >= 0.10 && proc90 < 0.30) {
        hb.getChildren().add(new ImageView(imYelow));
        vb.getChildren().add(new ImageView(imYelow));
      } else if (proc90 >= 0.30) {
        hb.getChildren().add(new ImageView(imGreen));
        vb.getChildren().add(new ImageView(imGreen));
      }
      tooltext
          .append("3 міс. {")
          .append(DateConverters.getDateToStr(per90From))
          .append(" - ")
          .append(DateConverters.getDateToStr(per60From))
          .append("}:  ")
          .append(String.format("%.2f", proc90 * 100))
          .append("%");
      tooltip.setText(tooltext.toString());
      tooltip.setGraphic(vb);
      setTooltip(tooltip);
      setGraphic(hb);
    } else {
      setGraphic(null);
    }
  }
}
 @Test(
     dataProvider = "samples",
     groups = {"tck"})
 public void test_toLocalDate(JapaneseDate jdate, LocalDate iso) {
   assertEquals(LocalDate.from(jdate), iso);
 }
Esempio n. 5
0
  @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"));
  }
 public void setTime(int hour, int minute, int second) {
   LocalDate currentDate = LocalDate.from(dateAndTime);
   LocalTime timeToSet = LocalTime.of(hour, minute, second);
   dateAndTime = LocalDateTime.of(currentDate, timeToSet);
 }