/** * Changes input calendar by resetting time fields to the begin of day. * * @param calendar the calendar to change; can't be null. * @return the changed calendar. */ public static Calendar dayBeginTime(Calendar calendar) { calendar.set(Calendar.HOUR, calendar.getMinimum(Calendar.HOUR)); calendar.set(Calendar.MINUTE, calendar.getMinimum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getMinimum(Calendar.SECOND)); calendar.set(Calendar.MILLISECOND, calendar.getMinimum(Calendar.MILLISECOND)); return calendar; }
public static Date addMinimunHour(Date date) { if (date == null) return null; calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, calendar.getMinimum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getMinimum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getMinimum(Calendar.SECOND)); calendar.set(Calendar.MILLISECOND, calendar.getMinimum(Calendar.MILLISECOND)); return calendar.getTime(); }
/** * Changes input calendar by resetting time fields to 0. * * @param calendar the calendar to change; can't be null. * @return the changed calendar. */ public static Calendar dateOnly(Calendar calendar) { ArgumentAssert.isNotNull(calendar, "Calendar can't be null."); calendar.set(Calendar.HOUR, calendar.getMinimum(Calendar.HOUR)); calendar.set(Calendar.MINUTE, calendar.getMinimum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getMinimum(Calendar.SECOND)); calendar.set(Calendar.MILLISECOND, calendar.getMinimum(Calendar.MILLISECOND)); return calendar; }
public static Date getPrimerDiaDelMes() { Calendar cal = Calendar.getInstance(); cal.set( cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.getActualMinimum(Calendar.DAY_OF_MONTH), cal.getMinimum(Calendar.HOUR_OF_DAY), cal.getMinimum(Calendar.MINUTE), cal.getMinimum(Calendar.SECOND)); return cal.getTime(); }
/** * 获取某月第一天 * * @param year * @param month * @return */ public static String getFirstDayOfMonth(int year, int month) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month - 1); cal.set(Calendar.DAY_OF_MONTH, cal.getMinimum(Calendar.DATE)); return new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); }
private String formatTimeFromHours(int timeInHours) { if (timeInHours < 0) { return null; } Calendar cDate = Calendar.getInstance(); cDate.clear(); cDate.set(Calendar.YEAR, 0); cDate.add(Calendar.HOUR, timeInHours); int years = cDate.get(Calendar.YEAR) - cDate.getMinimum(Calendar.YEAR); int months = cDate.get(Calendar.MONTH); int days = cDate.get(Calendar.DAY_OF_MONTH) - 1; int hours = cDate.get(Calendar.HOUR_OF_DAY); String yearsString = (years < 10) ? "0" + years : years + ""; String monthsString = (months < 10) ? "0" + months : months + ""; String daysString = (days < 10) ? "0" + days : days + ""; String hoursString = (hours < 10) ? "0" + hours : hours + ""; return yearsString + monthsString + daysString + hoursString + "0000000R"; }
@Override public void execute(Event<UIWeekView> event) throws Exception { UIWeekView calendarview = event.getSource(); UICalendarPortlet uiCalendarPortlet = calendarview.getAncestorOfType(UICalendarPortlet.class); String eventId = event.getRequestContext().getRequestParameter(OBJECTID); String calendarId = event.getRequestContext().getRequestParameter(eventId + CALENDARID); String calType = event.getRequestContext().getRequestParameter(eventId + CALTYPE); String startTime = event.getRequestContext().getRequestParameter(eventId + START_TIME); String finishTime = event.getRequestContext().getRequestParameter(eventId + FINISH_TIME); String currentDate = event.getRequestContext().getRequestParameter(eventId + CURRENT_DATE); Boolean isOccur = false; if (!Utils.isEmpty(event.getRequestContext().getRequestParameter(eventId + ISOCCUR))) { isOccur = Boolean.parseBoolean(event.getRequestContext().getRequestParameter(eventId + ISOCCUR)); } String recurId = null; if (isOccur) recurId = event.getRequestContext().getRequestParameter(eventId + RECURID); String username = CalendarUtils.getCurrentUser(); CalendarService calendarService = CalendarUtils.getCalendarService(); CalendarEvent eventCalendar = calendarview.getDataMap().get(eventId); if (isOccur && !Utils.isEmpty(recurId)) { eventCalendar = calendarview.getRecurrenceMap().get(eventId).get(recurId); } if (eventCalendar != null) { CalendarService calService = CalendarUtils.getCalendarService(); boolean isMove = false; try { org.exoplatform.calendar.service.Calendar calendar = null; if (eventCalendar.getCalType().equals(CalendarUtils.PRIVATE_TYPE)) { calendar = calService.getUserCalendar(username, calendarId); } else if (eventCalendar.getCalType().equals(CalendarUtils.SHARED_TYPE)) { if (calService.getSharedCalendars(username, true) != null) calendar = calService.getSharedCalendars(username, true).getCalendarById(calendarId); } else if (eventCalendar.getCalType().equals(CalendarUtils.PUBLIC_TYPE)) { calendar = calService.getGroupCalendar(calendarId); } if (calendar == null) { event .getRequestContext() .getUIApplication() .addMessage(new ApplicationMessage("UICalendars.msg.have-no-calendar", null, 1)); } else { Calendar cal = calendarview.getInstanceTempCalendar(); int hoursBg = (Integer.parseInt(startTime) / 60); int minutesBg = (Integer.parseInt(startTime) % 60); int hoursEnd = (Integer.parseInt(finishTime) / 60); int minutesEnd = (Integer.parseInt(finishTime) % 60); try { cal.setTimeInMillis(Long.parseLong(currentDate)); if (hoursBg < cal.getMinimum(Calendar.HOUR_OF_DAY)) { hoursBg = 0; minutesBg = 0; } cal.set(Calendar.HOUR_OF_DAY, hoursBg); cal.set(Calendar.MINUTE, minutesBg); isMove = (eventCalendar.getFromDateTime().getTime() != cal.getTimeInMillis()); eventCalendar.setFromDateTime(cal.getTime()); if (hoursEnd >= 24) { hoursEnd = 23; minutesEnd = 59; } cal.set(Calendar.HOUR_OF_DAY, hoursEnd); cal.set(Calendar.MINUTE, minutesEnd); eventCalendar.setToDateTime(cal.getTime()); } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("Fail when calculate the time for calendar", e); } return; } if (eventCalendar.getToDateTime().before(eventCalendar.getFromDateTime())) { return; } // if it's a 'virtual' occurrence if (isOccur && !Utils.isEmpty(recurId)) { if (!isMove) { UIPopupAction pAction = uiCalendarPortlet.getChild(UIPopupAction.class); UIConfirmForm confirmForm = pAction.activate(UIConfirmForm.class, 480); confirmForm.setConfirmMessage("update-recurrence-event-confirm-msg"); confirmForm.setDelete(false); confirmForm.setConfig_id(calendarview.getId()); calendarview.setCurrentOccurrence(eventCalendar); event.getRequestContext().addUIComponentToUpdateByAjax(pAction); } else { calService = CalendarUtils.getCalendarService(); CalendarEvent originEvent = calService.getRepetitiveEvent(eventCalendar); calService.saveOneOccurrenceEvent(originEvent, eventCalendar, username); } // return; // List<CalendarEvent> listEvent = new ArrayList<CalendarEvent>(); // listEvent.add(eventCalendar); // calendarService.updateOccurrenceEvent(calendarId, calendarId, calType, calType, // listEvent, username); } else { if (calType.equals(CalendarUtils.PRIVATE_TYPE)) { calendarService.saveUserEvent(username, calendarId, eventCalendar, false); } else if (calType.equals(CalendarUtils.SHARED_TYPE)) { calendarService.saveEventToSharedCalendar( username, calendarId, eventCalendar, false); } else if (calType.equals(CalendarUtils.PUBLIC_TYPE)) { calendarService.savePublicEvent(calendarId, eventCalendar, false); } } calendarview.setLastUpdatedEventId(eventId); calendarview.refresh(); UIMiniCalendar uiMiniCalendar = uiCalendarPortlet.findFirstComponentOfType(UIMiniCalendar.class); event.getRequestContext().addUIComponentToUpdateByAjax(uiMiniCalendar); if (isOccur) { event.getRequestContext().addUIComponentToUpdateByAjax(calendarview); } else { JavascriptManager jsManager = event.getRequestContext().getJavascriptManager(); RequireJS requireJS = jsManager.getRequireJS(); requireJS.require("PORTLET/calendar/CalendarPortlet", "cal"); requireJS.addScripts("cal.UIWeekView.setSize();cal.UIWeekView.cleanUp();"); } } } catch (PathNotFoundException e) { if (log.isDebugEnabled()) { log.debug("The calendar is not found", e); } event .getRequestContext() .getUIApplication() .addMessage(new ApplicationMessage("UICalendars.msg.have-no-calendar", null, 1)); } catch (Exception ex) { if (log.isDebugEnabled()) { log.debug("The calendar is not found", ex); } } } }