コード例 #1
0
  static LocalDateTime parse(String endDateTimeString) {

    String endDateString = null;
    String endTimeString = null;

    Pattern pattern = Pattern.compile(DATE_TIME_PATTERN);
    Matcher matcher = pattern.matcher(endDateTimeString);

    matcher.find();
    endDateString = matcher.group(1);
    endTimeString = matcher.group(2);

    if (endDateString == null) {
      endDateString = "today";
    }

    if (endTimeString == null) {
      endTimeString = END_TIME_DEFAULT;
    }

    LocalDate endDate = DateParser.parse(endDateString);
    LocalTime endTime = TimeParser.parse(endTimeString);

    LocalDateTime endDateTime = endDate.atTime(endTime);

    if (endDateTime.isBefore(LocalDateTime.now())) {
      endDateTime = endDateTime.plusDays(1);
    }

    return endDateTime;
  }
コード例 #2
0
  public static String getTimeUntilNow(String time) {
    LocalDateTime now = LocalDateTime.now();
    now = now.plusMinutes(1);

    int hours = Integer.parseInt(time.split(":")[0]);
    int minutes = Integer.parseInt(time.split(":")[1]);

    LocalDateTime tocheck =
        LocalDateTime.of(
            now.getYear(),
            now.getMonth(),
            now.getDayOfMonth(),
            hours,
            minutes,
            now.getSecond(),
            now.getNano());

    if (tocheck.isBefore(now)) {
      tocheck = tocheck.plusDays(1);
    }

    Duration remaining = Duration.between(now, tocheck);

    int rh = (int) remaining.toHours();
    int rm = (int) remaining.toMinutes();
    rm %= 60;

    int ht = rh / 10;
    int hs = rh % 10;
    int mt = rm / 10;
    int ms = rm % 10;

    return ht + "" + hs + ":" + mt + "" + ms;
  }
コード例 #3
0
  // start date before end date
  static LocalDateTime[] parse(String startDateTimeString, String endDateTimeString) {
    LocalDateTime[] dates = new LocalDateTime[2];
    String startDateString = null;
    String startTimeString = null;
    String endDateString = null;
    String endTimeString = null;

    Pattern pattern = Pattern.compile(DATE_TIME_PATTERN);

    Matcher matcher = pattern.matcher(startDateTimeString);
    matcher.find();
    startDateString = matcher.group(1);
    startTimeString = matcher.group(2);

    matcher = pattern.matcher(endDateTimeString);
    matcher.find();
    endDateString = matcher.group(1);
    endTimeString = matcher.group(2);

    if (startDateString == null) {
      startDateString = processNullStartDate(endDateString);
    }

    if (startDateString.equals("now")) {
      startTimeString = getCurrentTime();
    }

    if (endDateString == null) {
      endDateString = startDateString;
    }

    if (startTimeString == null) {
      startTimeString = processNullStartTime(startDateString);
    }

    if (endTimeString == null) {
      endTimeString = processNullEndTime(startDateString, endDateString, startTimeString);
    }

    LocalDate startDate = DateParser.parse(startDateString);
    LocalTime startTime = TimeParser.parse(startTimeString);
    LocalDateTime startDateTime = startDate.atTime(startTime);

    LocalDate endDate = DateParser.parse(endDateString);
    LocalTime endTime = TimeParser.parse(endTimeString);
    LocalDateTime endDateTime = endDate.atTime(endTime);

    if (endDateTime.isBefore(startDateTime)) {
      endDateTime.plusDays(1);
    }

    dates[0] = startDateTime;
    dates[1] = endDateTime;

    return dates;
  }
コード例 #4
0
ファイル: p019.java プロジェクト: sunnytran/Project-Euler
 public static void main(String args[]) {
   LocalDateTime dt = LocalDateTime.of(1901, 1, 1, 0, 0);
   LocalDateTime stop = LocalDateTime.of(2000, 12, 31, 0, 0);
   int count = 0;
   while (dt.compareTo(stop) != 0) {
     if (dt.getDayOfMonth() == 1 && dt.getDayOfWeek() == DayOfWeek.SUNDAY) count++;
     dt = dt.plusDays(1);
   }
   System.out.println(count);
 }
コード例 #5
0
  private void validateIntervalPosition(ConferenceInterval interval) {
    LocalDateTime startDateTime = interval.getStartDateTime();
    LocalDateTime endDateTime = interval.getEndDateTime();
    LocalDateTime now = LocalDateTime.now();

    LocalDateTime minStartDateTime = now.plusDays(MIN_TIME_BEFORE_CONFERENCE_START_IN_DAYS);

    if (startDateTime.isBefore(minStartDateTime)) {
      throw new ValidationException(
          String.format(
              "Conference must start after %s",
              minStartDateTime.format(CONFERENCE_DATE_TIME_FORMATTER)));
    }

    if (endDateTime.isBefore(startDateTime)) {
      throw new ValidationException(
          String.format(
              "Conference end dateTime %s is before start dateTime %s",
              endDateTime.format(CONFERENCE_DATE_TIME_FORMATTER),
              startDateTime.format(CONFERENCE_DATE_TIME_FORMATTER)));
    }
  }
コード例 #6
0
  /**
   * 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");
          }
        }
      }
    }
  }