private void validateIntervalDuration(ConferenceInterval interval) {
    LocalDateTime startDateTime = interval.getStartDateTime();
    LocalDateTime endDateTime = interval.getEndDateTime();

    long hours = startDateTime.until(endDateTime, ChronoUnit.HOURS);

    if (hours < MIN_CONFERENCE_DURATION_IN_HOURS) {
      throw new ValidationException(
          String.format(
              "Conference duration is %s hours, less than min of %s hour(s)",
              hours, MIN_CONFERENCE_DURATION_IN_HOURS));
    }

    long days = startDateTime.until(endDateTime, ChronoUnit.DAYS);

    if (days > MAX_CONFERENCE_DURATION_IN_DAYS) {
      throw new ValidationException(
          String.format(
              "Conference duration is %s days, more than max of %s day(s)",
              days, MAX_CONFERENCE_DURATION_IN_DAYS));
    }
  }
  /**
   * Uses <code>List workoutHistoryLog</code> to build the bar chart series:
   *
   * <ul>
   *   <li>Selects the last 7 days of workout history
   *   <li>retrieves history data and formats dates for <code>xDateAxis</code> and total workout
   *       time for that day for the <code>yWorkoutTimeAxis</code>
   *   <li>adds all data to the series
   * </ul>
   */
  private void makeWeekSeriesFromAccountHistory() {

    Locale eng = Locale.UK;
    LocalDateTime today = LocalDateTime.now();

    String inputPattern = "yyyyMMddHHmm";
    DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern(inputPattern, eng);

    String outputPattern = "EEEE"; // day with text
    DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputPattern, eng);

    // Variables for history entries
    String inputDate;
    long timeToComplete;

    // LocalDateTime object for input date
    LocalDateTime dateOfCompletion;
    // String output for axis
    String formattedDateForAxis;

    long lastDate;

    // Search all workout entries in account's workout history
    // parse the input date string into a LocalDateTime for pattern formatting
    // find entries that are within the last week
    // add date against workout time to series
    for (WorkoutEntry entry : workoutHistoryLog) {

      // Get workout date from history entry
      inputDate = entry.getWorkoutDate();
      dateOfCompletion = LocalDateTime.parse(inputDate, inputFormatter);

      formattedDateForAxis = dateOfCompletion.format(outputFormatter);

      // Check if within the last 7 days
      if (dateOfCompletion.until(today, ChronoUnit.WEEKS) == 0) {
        timeToComplete = entry.getWorkoutTime();
        seriesW.getData().add(new XYChart.Data(formattedDateForAxis, timeToComplete));
      }
    }
  }
Пример #3
0
 public MircString lanCountdown() {
   LocalDateTime lan = LocalDateTime.of(2016, 4, 29, 18, 0, 0);
   LocalDateTime now = LocalDateTime.now();
   Long seconds = now.until(lan, ChronoUnit.SECONDS);
   int totalSeconds = (60 * 60 * 24 * 365 * 1000);
   BigDecimal bigSeconds = new BigDecimal(totalSeconds);
   BigDecimal secondsLeft = new BigDecimal(seconds);
   BigDecimal millennia = secondsLeft.divide(bigSeconds, 50, RoundingMode.HALF_UP);
   String inputString =
       "There are "
           + seconds.toString()
           + " seconds to LAN - you'd better be prepared for it, mofos. Or, if you're Ragnar, there are "
           + millennia
           + " millennia left.";
   if (seconds < 0) {
     seconds = Math.abs(seconds);
     inputString = "LAN has been running for " + seconds.toString() + " seconds! Kick ass!";
   }
   MircString mircString = MircString.of(inputString.toString());
   return mircString;
 }
  /**
   * Uses <code>List workoutHistoryLog</code> to build the bar chart series:
   *
   * <ul>
   *   <li>Selects the last 30 days of workout history
   *   <li>retrieves history data and formats dates for <code>xDateAxis</code> and total workout
   *       time for that day for the <code>yWorkoutTimeAxis</code>
   *   <li>adds all data to the series
   * </ul>
   */
  private void makeMonthSeriesFromAccountHistory() {

    Locale eng = Locale.UK;
    LocalDateTime today = LocalDateTime.now();

    String inputPattern = "yyyyMMddHHmm";
    DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern(inputPattern, eng);

    String outputPattern = "dd/MM"; // day with text
    DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputPattern, eng);

    // Variables for history entries
    String inputDate;
    long timeToComplete;
    long input;

    // LocalDateTime object for input date
    LocalDateTime dateOfCompletion;
    // LocalDateTime newDate = LocalDateTime.of(1900, 05, 16, 03);

    // String output for axis
    String formattedDateForAxis;

    // Search all workout entries in account's workout history
    // parse the input date string into a LocalDateTime for pattern formatting
    // find entries that are within the last week
    // add date against workout time to series
    for (int i = 0; i < workoutHistoryLog.size(); i++) {

      // Get workout date from history entry
      inputDate = workoutHistoryLog.get(i).getWorkoutDate();
      // input = Long.parseLong(inputDate);

      dateOfCompletion = LocalDateTime.parse(inputDate, inputFormatter);

      formattedDateForAxis = dateOfCompletion.format(outputFormatter);

      // Check if within the last month
      if (dateOfCompletion.until(today, ChronoUnit.MONTHS) == 0) {

        timeToComplete = workoutHistoryLog.get(i).getWorkoutTime();

        seriesM.getData().add(new XYChart.Data(formattedDateForAxis, timeToComplete));

        if (i != workoutHistoryLog.size() - 1) {
          int diff = getDifference(inputDate, workoutHistoryLog.get(i + 1).getWorkoutDate());
          LocalDateTime noWorkoutDate = dateOfCompletion;

          if (diff > 1) {
            for (int j = 0; j < diff - 1; j++) {
              noWorkoutDate.plusDays(j + 1);
              System.out.println(noWorkoutDate.plusDays(j + 1).format(outputFormatter));
              seriesM
                  .getData()
                  .add(new XYChart.Data(noWorkoutDate.plusDays(j + 1).format(outputFormatter), 0));
            }
            System.out.println("out");
          }
        }
      }
    }
  }