/**
   * Do get.
   *
   * @param request the request
   * @param response the response
   * @throws ServletException the servlet exception
   * @throws IOException Signals that an I/O exception has occurred.
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    try {

      // maak een lijst van dagen: dayofweek, date, hoogste laagste, open, slot, vorige slot
      // deze waarden halen we uit een properties file
      // sorted on date
      // we gaan max 3 weken terug

      // 1 = maandag, 5 = vrijdag

      // Set the attribute and Forward to hello.jsp
      List<String> files = FileUtils.getFiles(Constants.INTRADAY_KOERSENDIR, "csv", false);

      DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyyMMdd");
      int days = files.size();
      Map<Integer, Map<Integer, String>> matrix = new HashMap<Integer, Map<Integer, String>>();
      int weekNumberOld = 0;
      Map<Integer, String> week = null;
      int weekNumber = 0;
      if (days < numberOfDays) {
        numberOfDays = days;
      }
      for (int i = days - numberOfDays; i < days; i++) {
        String file = files.get(i);
        DateTime dt = formatter.parseDateTime(file);
        weekNumber = dt.getWeekOfWeekyear();
        if (weekNumber != weekNumberOld) {
          if (week != null) {
            matrix.put(-weekNumberOld, week);
          }
          weekNumberOld = weekNumber;
          week = new HashMap<Integer, String>();
          week.put(1, "");
          week.put(2, "");
          week.put(3, "");
          week.put(4, "");
          week.put(5, "");
        }
        week.put(dt.getDayOfWeek(), file);

        System.out.println(
            "file: " + file + " dayofweek: " + dt.getDayOfWeek() + dt.getWeekOfWeekyear());
      }
      if (!matrix.containsKey(weekNumber)) {
        matrix.put(-weekNumber, week);
      }
      request.setAttribute("matrix", matrix);
      request.setAttribute("dir", "intraday");
      getServletConfig()
          .getServletContext()
          .getRequestDispatcher("/intradayoverview.jsp")
          .forward(request, response);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
    /**
     * returns based on DateTime if is in business hours
     *
     * @param dateTimeString
     * @param dateTimeFormatter
     * @return
     */
    private static BusinessHours isBusinessHours(
        String dateTimeString, DateTimeFormatter dateTimeFormatter) {
      DateTime dateTime = DateTime.parse(dateTimeString, dateTimeFormatter);

      // Weekends
      int day = dateTime.getDayOfWeek();
      if (day > DateTimeConstants.FRIDAY) {
        return BusinessHours.NOPE;
      }

      int minute = dateTime.getMinuteOfDay();

      // GOOD = 9-17
      if (minute >= TimeUnit.HOURS.toMinutes(9) && minute <= TimeUnit.HOURS.toMinutes(17)) {
        return BusinessHours.GOOD;
      }

      // OK = 0800-0859, 1701-1800
      if (minute >= TimeUnit.HOURS.toMinutes(8) && minute < TimeUnit.HOURS.toMinutes(9)
          || (minute > TimeUnit.HOURS.toMinutes(17) && minute <= TimeUnit.HOURS.toMinutes(18))) {
        return BusinessHours.OK;
      }

      // MEH = 0700-0759, 1801-1900
      if (minute >= TimeUnit.HOURS.toMinutes(7) && minute < TimeUnit.HOURS.toMinutes(8)
          || (minute > TimeUnit.HOURS.toMinutes(18) && minute <= TimeUnit.HOURS.toMinutes(19))) {
        return BusinessHours.MEH;
      }

      return BusinessHours.NOPE;
    }
Example #3
0
    @Specialization
    public RubyBasicObject timeDecompose(VirtualFrame frame, RubyTime time) {
      CompilerDirectives.transferToInterpreter();
      final DateTime dateTime = time.getDateTime();
      final int sec = dateTime.getSecondOfMinute();
      final int min = dateTime.getMinuteOfHour();
      final int hour = dateTime.getHourOfDay();
      final int day = dateTime.getDayOfMonth();
      final int month = dateTime.getMonthOfYear();
      final int year = dateTime.getYear();

      int wday = dateTime.getDayOfWeek();

      if (wday == 7) {
        wday = 0;
      }

      final int yday = dateTime.getDayOfYear();
      final boolean isdst = false;

      final String envTimeZoneString = readTimeZoneNode.executeRubyString(frame).toString();
      String zoneString = org.jruby.RubyTime.zoneHelper(envTimeZoneString, dateTime, false);
      Object zone;
      if (zoneString.matches(".*-\\d+")) {
        zone = nil();
      } else {
        zone = createString(zoneString);
      }

      final Object[] decomposed =
          new Object[] {sec, min, hour, day, month, year, wday, yday, isdst, zone};
      return createArray(decomposed, decomposed.length);
    }
 // @VisibleForTesting
 DateTime getNthDOWOfMonth(DateTime midnightTomorrow, Integer nthOfMonth, Integer dow) {
   int dtconstDow = dow == 0 ? 7 : dow;
   DateTime first = midnightTomorrow.withDayOfMonth(1);
   if (first.getDayOfWeek() > dtconstDow) {
     return first.plusWeeks(nthOfMonth).withDayOfWeek(dtconstDow);
   } else {
     return first.plusWeeks(nthOfMonth - 1).withDayOfWeek(dtconstDow);
   }
 }
 private DateTime scheduleWeekday(DateTime now) {
   DateTime nowMidnight = now.toDateMidnight().toDateTime();
   if (nowMidnight.getDayOfWeek()
       < DateTimeConstants.SATURDAY) { // jodatime starts with Monday = 0
     DateTime nextTimeToday = getNextTimeToday(now, nowMidnight);
     if (nextTimeToday != null) {
       return nextTimeToday;
     }
   }
   DateTime nextDay = getNextScheduleDay(nowMidnight.plusDays(1));
   return getFirstScheduledTimeOnDay(nextDay);
 }
Example #6
0
 private int calcWorkingDayNum() {
   DateTime start = sprint.getStartDate();
   DateTime end = sprint.getEndDate();
   start = start.minusMillis(start.millisOfDay().get());
   end = end.minusMillis(end.millisOfDay().get());
   int i = 0;
   for (; start.isBefore(end); start = start.plusDays(1)) {
     if (start.getDayOfWeek() < DateTimeConstants.SATURDAY) {
       i++;
     }
   }
   return i;
 }
  /**
   * Gets all expirations for the current symbol and then excludes dates that are not part of the
   * monthly expirations. Dates are 15th - 22nd, if it's the 22nd, then the 22nd has to be a Sat
   *
   * <p>There are some expirations on Friday and Sat where 1 of the 2 only has a few options
   * available.
   *
   * @return monthly expirations
   */
  public List<Date> getMonthlyExpirations() {

    List<Date> monthlyExpirations = new ArrayList<Date>();
    List<Date> allExpirations = getExpirations();

    for (Date date : allExpirations) {
      DateTime jDate = new DateTime(date);
      if (jDate.dayOfMonth().get() >= 15 && jDate.dayOfMonth().get() <= 22) {
        if ((jDate.dayOfMonth().get() == 22 && jDate.getDayOfWeek() != DateTimeConstants.SATURDAY)
            || jDate.getDayOfWeek() == DateTimeConstants.SUNDAY
            || jDate.getDayOfWeek() == DateTimeConstants.MONDAY
            || jDate.getDayOfWeek() == DateTimeConstants.TUESDAY
            || jDate.getDayOfWeek() == DateTimeConstants.WEDNESDAY
            || jDate.getDayOfWeek() == DateTimeConstants.THURSDAY) {
          // skip
        } else {
          // System.out.println(jDate.toString() + " - " + jDate.getDayOfWeek());
          monthlyExpirations.add(date);
        }
      }
    }
    return monthlyExpirations;
  }
 private DateTime scheduleWeekly(DateTime now) {
   DateTime nowMidnight = now.toDateMidnight().toDateTime();
   int nowDow = nowMidnight.getDayOfWeek(); // joda starts Monday, I start Sunday
   Integer nowDowIndex =
       Schedule.DAYS_OF_WEEK[
           nowDow == 7
               ? 0
               : nowDow]; // joda is 1 based, and starts on Monday. we are 0-based, Sunday-start
   if ((schedule.getWeekDaysScheduled() & nowDowIndex) == nowDowIndex) {
     DateTime nextTimeToday = getNextTimeToday(now, nowMidnight);
     if (nextTimeToday != null) {
       return nextTimeToday;
     }
   }
   DateTime nextDay = getNextScheduleDay(nowMidnight.plusDays(1));
   return getFirstScheduledTimeOnDay(nextDay);
 }
 public boolean isCurrentTimeInSchedule() {
   DateTime now = DateTime.now();
   if (dayOfWeekRange != null && !dayOfWeekRange.contains(now.getDayOfWeek())) {
     return false;
   }
   if (dayOfMonthRange != null && !dayOfMonthRange.contains(now.getDayOfMonth())) {
     return false;
   }
   if (timeRange != null) {
     Interval interval =
         new Interval(
             timeRange.getLeft().toDateTimeToday(), timeRange.getRight().toDateTimeToday());
     if (!interval.contains(now)) {
       return false;
     }
   }
   return true;
 }
Example #10
0
  /** TV */
  @RequestMapping(value = "/manage")
  public String index(Model model) {

    List<Tv> tvs = tvService.selectTvs();

    DateTime dateTime = new DateTime();
    int dayOfWeek = dateTime.getDayOfWeek();

    dayOfWeek = dayOfWeek - 1;

    if (dayOfWeek == 0) {
      dayOfWeek = 7;
    }

    model.addAttribute("dayOfWeek", dayOfWeek);
    model.addAttribute("tvs", tvs);

    return "index";
  }
  @Override
  protected void initialize() {
    mPresenter = new MyStatPresenter(getActivity());
    mPresenter.setView(this);

    appPreferences = new TrayAppPreferences(getActivity());
    DateTime dateTime = DateTime.now();
    int dayOfWeek = dateTime.getDayOfWeek();
    boolean resetData;

    if (dayOfWeek == 1) {
      // It's Monday, check if data should be reset
      resetData = appPreferences.getBoolean(PREF_DATA_SHOULD_RESET, false);
    } else {
      // Not Monday, don't reset data
      resetData = false;
      // Set to true so that when it's Monday it resets again
      appPreferences.put(PREF_DATA_SHOULD_RESET, true);
    }

    mPresenter.getChartValues(resetData);
  }
Example #12
0
 private DateTime nextRepeatWeekly(DateTime midnightNextDay) {
   if (schedule.getRepeatRate() == 1) {
     return midnightNextDay;
   }
   int distanceBetweenStartAndTomorrow =
       Weeks.weeksBetween(new DateTime(schedule.getBeginDate()).toDateMidnight(), midnightNextDay)
           .getWeeks();
   if (distanceBetweenStartAndTomorrow == 0
       || distanceBetweenStartAndTomorrow == schedule.getRepeatRate()) {
     if ((distanceBetweenStartAndTomorrow == 0
         && midnightNextDay.getDayOfWeek()
             <= new DateMidnight(schedule.getBeginDate()).getDayOfWeek())) {
       // we crossed a week boundary, so add one week.
       return midnightNextDay.plusWeeks(schedule.getRepeatRate() - 1);
     }
     return midnightNextDay;
   } else if (distanceBetweenStartAndTomorrow > schedule.getRepeatRate()) {
     int remainder = distanceBetweenStartAndTomorrow % schedule.getRepeatRate();
     return midnightNextDay.plusWeeks(schedule.getRepeatRate() - remainder);
   } else {
     return midnightNextDay.plusWeeks(schedule.getRepeatRate() - distanceBetweenStartAndTomorrow);
   }
 }
Example #13
0
  @SuppressWarnings("unchecked")
  @ResponseBody
  @RequestMapping(value = "/order/deliveryEdit.ajax", method = RequestMethod.POST)
  public ResponseEntity<byte[]> buildDeliveryEdit(@RequestParam(value = "orderId") String orderId)
      throws Exception {

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Building delivery options for orderId: " + orderId);
    }

    Map<String, Object> model = new HashMap<String, Object>();

    try {
      Order order = orderRepository.findByOrderId(orderId);
      Restaurant restaurant = order.getRestaurant();

      // Get opening times for today and the next three days
      DateTime currentTime = new DateTime();
      DateTime now =
          new DateTime(
              currentTime.getYear(),
              currentTime.getMonthOfYear(),
              currentTime.getDayOfMonth(),
              currentTime.getHourOfDay(),
              currentTime.getMinuteOfHour(),
              0,
              0);

      // Store if the restaurant is currently open
      boolean isOpen = restaurant.isOpen(currentTime);

      List<Integer> days = new ArrayList<Integer>();
      List<Set<LocalTime>> deliveryTimes = new ArrayList<Set<LocalTime>>();
      List<Set<LocalTime>> collectionTimes = new ArrayList<Set<LocalTime>>();

      // Get the remaining options for today first
      days.add(now.getDayOfWeek());
      DateTime[] openingAndClosingTimes = restaurant.getOpeningAndClosingTimes(now);
      DateTime earlyOpeningTime =
          openingAndClosingTimes[0] == null ? now : openingAndClosingTimes[0];
      DateTime lateOpeningTime =
          openingAndClosingTimes[2] == null ? now : openingAndClosingTimes[2];

      // For delivery times push the current time past the delivery time in minutes
      int deliveryTimeMinutes = restaurant.getDeliveryTimeMinutes();
      Pair<Set<LocalTime>, Set<LocalTime>> earlyDeliveryTimesPair =
          getTimeOptions(
              now.isBefore(earlyOpeningTime) ? earlyOpeningTime : now,
              openingAndClosingTimes[1],
              deliveryTimeMinutes);
      Pair<Set<LocalTime>, Set<LocalTime>> lateDeliveryTimesPair =
          getTimeOptions(
              now.isBefore(lateOpeningTime) ? lateOpeningTime : now,
              openingAndClosingTimes[3],
              deliveryTimeMinutes);
      earlyDeliveryTimesPair.first.addAll(lateDeliveryTimesPair.first);
      earlyDeliveryTimesPair.second.addAll(lateDeliveryTimesPair.second);

      // For delivery times push the current time past the collection time in minutes
      int collectionTimeMinutes = restaurant.getCollectionTimeMinutes();
      Pair<Set<LocalTime>, Set<LocalTime>> earlyCollectionTimesPair =
          getTimeOptions(
              now.isBefore(earlyOpeningTime) ? earlyOpeningTime : now,
              openingAndClosingTimes[1],
              collectionTimeMinutes);
      Pair<Set<LocalTime>, Set<LocalTime>> lateCollectionTimesPair =
          getTimeOptions(
              now.isBefore(lateOpeningTime) ? lateOpeningTime : now,
              openingAndClosingTimes[3],
              collectionTimeMinutes);
      earlyCollectionTimesPair.first.addAll(lateCollectionTimesPair.first);
      earlyCollectionTimesPair.second.addAll(lateCollectionTimesPair.second);

      // Add today's opening times
      deliveryTimes.add(earlyDeliveryTimesPair.first);
      collectionTimes.add(earlyCollectionTimesPair.first);

      // Now get the rest of the options for the remaining times
      for (int i = 0; i < 3; i++) {

        // Add any times after midnight from the previous list
        Set<LocalTime> deliveryTimesSet = new TreeSet<LocalTime>();
        Set<LocalTime> collectionTimesSet = new TreeSet<LocalTime>();
        deliveryTimesSet.addAll(earlyDeliveryTimesPair.second);
        collectionTimesSet.addAll(earlyCollectionTimesPair.second);

        // Now get the next set of opening and closing times
        now = now.plusDays(1);
        days.add(now.getDayOfWeek());

        openingAndClosingTimes = restaurant.getOpeningAndClosingTimes(now);
        earlyDeliveryTimesPair =
            getTimeOptions(
                openingAndClosingTimes[0], openingAndClosingTimes[1], deliveryTimeMinutes);
        lateDeliveryTimesPair =
            getTimeOptions(
                openingAndClosingTimes[2], openingAndClosingTimes[3], deliveryTimeMinutes);
        earlyDeliveryTimesPair.first.addAll(lateDeliveryTimesPair.first);
        earlyDeliveryTimesPair.second.addAll(lateDeliveryTimesPair.second);

        earlyCollectionTimesPair =
            getTimeOptions(
                openingAndClosingTimes[0], openingAndClosingTimes[1], collectionTimeMinutes);
        lateCollectionTimesPair =
            getTimeOptions(
                openingAndClosingTimes[2], openingAndClosingTimes[3], collectionTimeMinutes);
        earlyCollectionTimesPair.first.addAll(lateCollectionTimesPair.first);
        earlyCollectionTimesPair.second.addAll(lateCollectionTimesPair.second);

        // Add this day's time options to the list
        deliveryTimesSet.addAll(earlyDeliveryTimesPair.first);
        collectionTimesSet.addAll(earlyCollectionTimesPair.first);

        // Add these lists to the return
        deliveryTimes.add(deliveryTimesSet);
        collectionTimes.add(collectionTimesSet);
      }

      // Add the time options to the model
      model.put("days", days);
      model.put("deliveryTimes", deliveryTimes);
      model.put("collectionTimes", collectionTimes);
      model.put("collectionOnly", restaurant.getCollectionOnly());
      model.put("open", isOpen);
      model.put("success", true);

    } catch (Exception ex) {
      LOGGER.error("", ex);
      model.put("success", false);
      model.put("message", ex.getMessage());
    }
    return buildOrderResponse(model);
  }
Example #14
0
  private DateTime getNextScheduleDay(DateTime midnightTomorrow) {

    switch (schedule.getScheduleType()) {
      case Schedule.DAILY:
        return nextRepeatDaily(midnightTomorrow);

      case Schedule.WEEKDAY:
        int tomorrowDOW = midnightTomorrow.getDayOfWeek();
        if (tomorrowDOW > DateTimeConstants.FRIDAY) {
          return midnightTomorrow.plusDays(8 - tomorrowDOW);
        } else {
          return midnightTomorrow;
        }

      case Schedule.WEEKLY:
        int scheduleDays = schedule.getWeekDaysScheduled();
        if (scheduleDays == 0) {
          return null;
        }
        for (int i = 0; i < 8; i++) { // go at least to the same day next week.
          int midnightTomorrowDOW = midnightTomorrow.getDayOfWeek();
          Integer nowDowIndex =
              Schedule.DAYS_OF_WEEK[
                  midnightTomorrowDOW == 7
                      ? 0
                      : midnightTomorrowDOW]; // joda is 1 based & counts Monday as first day of the
                                              // week so Sunday is 7 instead of 0.
          if ((scheduleDays & nowDowIndex) == nowDowIndex) {
            return nextRepeatWeekly(midnightTomorrow);
          }
          midnightTomorrow = midnightTomorrow.plusDays(1);
        }
        throw new IllegalStateException(
            "Cannot get to here. Weekly must repeat at least once a week");

      case Schedule.MONTHLY:
        if (schedule.getByDayOfMonth()) {
          int midnightDOM = midnightTomorrow.getDayOfMonth();
          int scheduledDOM = schedule.getDayOfMonth();
          if (midnightDOM == scheduledDOM) {
            return midnightTomorrow;
          } else if (midnightDOM > scheduledDOM) {
            MutableDateTime mutableDateTime = midnightTomorrow.plusMonths(1).toMutableDateTime();
            mutableDateTime.setDayOfMonth(scheduledDOM);
            return nextRepeatMonthly(mutableDateTime.toDateTime());
          } else {
            return nextRepeatMonthly(midnightTomorrow.plusDays(scheduledDOM - midnightDOM));
          }
        } else {
          Integer nthOfMonth = schedule.getNthOfMonth();
          Integer dow =
              getDOWFromIndexedValue(); // only one selection, so take log2 to get index of dow
          DateMidnight nthDowDate =
              getNthDOWOfMonth(midnightTomorrow, nthOfMonth, dow).toDateMidnight();
          DateTime returnDate = null;
          if (nthDowDate.equals(midnightTomorrow)) {
            returnDate = midnightTomorrow;
          } else if (nthDowDate.isAfter(midnightTomorrow)) {
            returnDate = nthDowDate.toDateTime();
          } else {
            returnDate =
                getNthDOWOfMonth(midnightTomorrow.plusMonths(1), nthOfMonth, dow).toDateTime();
          }
          return nextRepeatMonthly(returnDate);
        }
      default:
        throw new IllegalStateException(
            "Schedule has an unknown type: " + schedule.getScheduleType());
    }
  }
Example #15
0
 @JRubyMethod(name = "wday")
 public RubyInteger wday() {
   return getRuntime().newFixnum((dt.getDayOfWeek() % 7));
 }
Example #16
0
 public boolean isSunday() {
   return flooredDate.getDayOfWeek() == DateTimeConstants.SUNDAY;
 }
Example #17
0
 public boolean isSaturday() {
   return flooredDate.getDayOfWeek() == DateTimeConstants.SATURDAY;
 }
Example #18
0
 public String getDayString(DateTime time) {
   String dayString = getString(DAY_OF_WEEK[time.getDayOfWeek()]);
   return dayString + " " + DAY_FORMAT.print(time);
 }
  /**
   * @Title: getOpenTimeByOrderDate @Description: 返回营业时间段
   *
   * @param:
   * @return: String[]
   */
  @Override
  public String[] getOpenTimeByOrderDate(Date orderDate, String restaurantUuid, int type) {
    int pickupInterval = 20;
    int deliveryInterval = 45;

    // Get the restaurant's local time.
    // TODO: This assumes users are in the same time zone as the restaurant!!
    Restaurants restaurant = restaurantsDao.getRestaurantsByUuid(restaurantUuid);
    double latitude = restaurant.getRestaurantLat();
    double longitude = restaurant.getRestaurantLng();
    Date originalAdjustedDate = GoogleTimezoneAPIUtil.getLocalDateTime(latitude, longitude);
    DateTime originalAdjustedDateTime = new DateTime(originalAdjustedDate);

    System.out.println("local time: " + originalAdjustedDate.toString());
    System.out.println("order day: " + orderDate.toString());

    try {
      // 注释掉的是之前做的开始时间结束时间都减少15分钟的方案, 现在是不减时间的
      String orderDateStr = new SimpleDateFormat("yyyy-MM-dd").format(orderDate);

      // If the request's date is before the restaurant's local date, return null.
      if (orderDate.before(
          new SimpleDateFormat("yyyy-MM-dd")
              .parse(originalAdjustedDateTime.toString("yyyy-MM-dd")))) {
        return null;
      }

      // Create a string to store the available times.
      StringBuffer buffer = new StringBuffer();
      String startStr = "";

      // Get the times the restaurant is open for the request's date.
      DateTime orderDateTime = new DateTime(orderDate);
      int week = orderDateTime.getDayOfWeek();
      List<OpenTime> list = openTimeDao.getOpenTime(restaurantUuid, type, week);
      for (OpenTime openTime : list) {
        // If the request's date matches the restaurant's local date, use the restaurant's local
        // time as the start time.
        // Otherwise, use the restaurant's start time as the start time.
        String startTime = openTime.getStarttime();
        String endTime = openTime.getEndtime();
        if (orderDate.equals(originalAdjustedDate)) {
          startTime = originalAdjustedDateTime.toString("HH:mm");
        }

        DateTime nowDateTime = originalAdjustedDateTime;

        // 现在时间加半小时在开门时间之后
        if (originalAdjustedDate.after(
            new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(orderDateStr + " " + startTime))) {

          if (type == GlobalConstant.TYPE_PICKUP) {
            nowDateTime = nowDateTime.plusMinutes(pickupInterval);
          } else if (type == GlobalConstant.TYPE_DELIVERY) {
            nowDateTime = nowDateTime.plusMinutes(deliveryInterval);
          } else {
            //// calendar.setTime(new Date());
          }

          // Apply hour offset to get to the current time zone
          int currentH = nowDateTime.getHourOfDay();
          int currentM = nowDateTime.getMinuteOfHour();

          System.out.println("  Time: " + currentH + ":" + currentM);

          if (currentM > 0 && currentM <= 15) {
            startStr = currentH + ":15";
          } else if (currentM > 15 && currentM <= 30) {
            startStr = currentH + ":30";
          } else if (currentM > 30 && currentM <= 45) {
            startStr = currentH + ":45";
          } else if (currentM > 45 && currentM <= 59) {
            currentH += 1;
            startStr = currentH + ":00";
          } else {
            startStr = currentH + ":15";
          }
        } else {
          int startH = Integer.parseInt(startTime.split(":")[0]);
          int startM = Integer.parseInt(startTime.split(":")[1]);
          startStr = startH + ":" + startM;
        }
        Date start = new SimpleDateFormat("HH:mm").parse(startStr);
        DateTime startDateTime = new DateTime(start);

        // Add a case for 00:00.
        if (startTime.equals("00:00") && orderDate.after(originalAdjustedDate)) {
          buffer.append("00:00,");
        }

        // Loop through all possible times of the day, ignoring midnight.
        while (!(getDateFromDateTime(startDateTime)
            .after(new SimpleDateFormat("HH:mm").parse(endTime)))) {
          String openTimeToAppend =
              new SimpleDateFormat("HH:mm").format(getDateFromDateTime(startDateTime));
          if (!openTimeToAppend.equals("00:00")) {
            buffer.append(openTimeToAppend + ",");
          }
          startDateTime = startDateTime.plusMinutes(15);
        }

        // Add a case for 24:00, since it gets parsed to be 00:00.
        if (endTime.equals("24:00")) {
          buffer.append("24:00,");
        }
      }
      String[] strs = buffer.toString().split(",");
      // 去除可能存在的重复
      List<String> list1 = new ArrayList<String>();
      for (String str : strs) {
        if (!list1.contains(str)) {
          list1.add(str);
        }
      }
      return (String[]) list1.toArray(new String[list1.size()]);
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return null;
    }
  }
Example #20
0
 public static DayOfTheWeek fromDateTime(DateTime dt) {
   return fromInt(dt.getDayOfWeek());
 }