@RequestMapping(value = "/move", method = RequestMethod.POST)
  @ResponseBody
  public String moveCalendar(
      @RequestParam("id") Long id,
      @RequestParam(value = "start", required = false) @DateTimeFormat(pattern = dataFormat)
          Date start,
      @RequestParam(value = "end", required = false) @DateTimeFormat(pattern = dataFormat)
          Date end) {
    Calendar calendar = calendarService.findOne(id);

    if (end == null) {
      end = start;
    }

    calendar.setStartDate(start);
    calendar.setLength((int) Math.ceil(1.0 * (end.getTime() - start.getTime()) / oneDayMillis));
    if (DateUtils.isSameDay(start, end)) {
      calendar.setLength(1);
    }
    if (!"00:00:00".equals(DateFormatUtils.format(start, "HH:mm:ss"))) {
      calendar.setStartTime(start);
    }
    if (!"00:00:00".equals(DateFormatUtils.format(end, "HH:mm:ss"))) {
      calendar.setEndTime(end);
    }
    calendarService.copyAndRemove(calendar);

    return "ok";
  }
  @RequestMapping(value = "/new", method = RequestMethod.GET)
  public String showNewForm(
      @RequestParam(value = "start", required = false) @DateTimeFormat(pattern = dataFormat)
          Date start,
      @RequestParam(value = "end", required = false) @DateTimeFormat(pattern = dataFormat) Date end,
      Model model) {

    setColorList(model);

    Calendar calendar = new Calendar();
    calendar.setLength(1);
    if (start != null) {
      calendar.setStartDate(start);
      calendar.setLength((int) Math.ceil(1.0 * (end.getTime() - start.getTime()) / oneDayMillis));
      if (DateUtils.isSameDay(start, end)) {
        calendar.setLength(1);
      }
      if (!"00:00:00".equals(DateFormatUtils.format(start, "HH:mm:ss"))) {
        calendar.setStartTime(start);
      }
      if (!"00:00:00".equals(DateFormatUtils.format(end, "HH:mm:ss"))) {
        calendar.setEndTime(end);
      }
    }
    model.addAttribute("model", calendar);
    return viewName("newForm");
  }
  public String getStyleForDate(int year, int month, int date, TimeZone timeZone) {
    String cellStyle = null;
    if (timeZone == null) {
      timeZone = getTimeZone();
    }

    GregorianCalendar dateCompareCalendar = new GregorianCalendar(timeZone);
    dateCompareCalendar.set(GregorianCalendar.YEAR, year);
    dateCompareCalendar.set(GregorianCalendar.MONTH, month);
    dateCompareCalendar.set(GregorianCalendar.DATE, date);
    dateCompareCalendar =
        (GregorianCalendar) DateUtils.truncate(dateCompareCalendar, GregorianCalendar.DATE);

    for (Entry<Long, String> entryCellStyle : getCellStyles().entrySet()) {
      GregorianCalendar cellStyleCalendar = new GregorianCalendar(timeZone);
      cellStyleCalendar.setTimeInMillis(entryCellStyle.getKey());

      // If selected month and year equals timestamp of cell style
      if (DateUtils.isSameDay(dateCompareCalendar, cellStyleCalendar)) {
        cellStyle = entryCellStyle.getValue();
      }
    }

    return cellStyle;
  }
  /**
   * This method returns all events for a specified date (year, month, date)<br>
   *
   * @param year e.g. 2010
   * @param month e.g. 11 for November
   * @param date e.g. 12
   * @return Collection of all events, which are planned for the specified date.
   */
  public Collection<CalendarEvent> getAllEventsForDate(
      int year, int month, int date, TimeZone timeZone) {
    // Get all events
    Collection<CalendarEvent> events = getCalendarEvents();
    Collection<CalendarEvent> dateEvents = new ArrayList<CalendarEvent>();

    GregorianCalendar dateCompareCalendar = new GregorianCalendar(timeZone);
    dateCompareCalendar.set(GregorianCalendar.YEAR, year);
    dateCompareCalendar.set(GregorianCalendar.MONTH, month);
    dateCompareCalendar.set(GregorianCalendar.DATE, date);
    dateCompareCalendar.set(GregorianCalendar.HOUR_OF_DAY, 00);
    dateCompareCalendar =
        (GregorianCalendar) DateUtils.truncate(dateCompareCalendar, GregorianCalendar.HOUR_OF_DAY);

    Iterator<CalendarEvent> eventsIter = events.iterator();
    while (eventsIter.hasNext()) {
      CalendarEvent event = eventsIter.next();
      GregorianCalendar eventCalendar = new GregorianCalendar(timeZone);
      eventCalendar.setTimeInMillis(event.getTimestampInMillis());

      // If selected month and year equals event in collection
      if (DateUtils.isSameDay(dateCompareCalendar, eventCalendar)) {
        dateEvents.add(event);
      }
    }
    // TODO Sort per hours
    return dateEvents;
  }
Esempio n. 5
0
  @Test
  public void testReadFixedRows() throws Exception {
    ExcelRange range = ExcelRange.sheetIndex(0).rowFrom(1).rowTo(2).columnRange("A", "G");
    ExcelRangeData data = instance.readRange(range);
    assertEquals(2, data.getRowCount());

    assertEquals("suilink", data.getString(0, 0));
    assertEquals("广州穗灵通讯科技有限公司", data.getString(0, 1));
    assertTrue(DateUtils.isSameDay(data.getDate(0, 2), parseDate(2002, 7, 1)));
    assertNull(data.getDate(0, 3));
    assertEquals(1, data.getInt(0, 4).intValue());
    assertEquals(1L, data.getLong(0, 4).longValue());
    assertEquals(1.0, data.getDouble(0, 4).doubleValue(), 0.0001);
    assertNull(data.getDate(0, 5));
    assertFalse(data.getBoolean(0, 6));
    assertTrue(data.getBoolean(1, 6));
  }
Esempio n. 6
0
 /**
  * 判断两个日历天是否同一天(忽略时间部分)
  *
  * @param date1
  * @param date2
  * @return
  */
 public static boolean isSameDay(Calendar date1, Calendar date2) {
   return org.apache.commons.lang3.time.DateUtils.isSameDay(date1, date2);
 }
Esempio n. 7
0
 private boolean isToday(String day) throws ParseException {
   Date currentDate = new Date();
   SimpleDateFormat sdf = new SimpleDateFormat(Day.dateFormat);
   Date date = sdf.parse(day);
   return DateUtils.isSameDay(date, currentDate);
 }