List of usage examples for java.util Calendar clone
@Override
public Object clone()
From source file:com.zimbra.cs.mailbox.calendar.ZRecur.java
private List<Calendar> expandYearDayList(List<Calendar> list) { // this func ONLY works for expanding, NOT for contracting assert (mFreq == Frequency.YEARLY); if (mByYearDayList.size() <= 0) return list; List<Calendar> toRet = new LinkedList<Calendar>(); Set<Integer> years = new HashSet<Integer>(); for (Calendar cur : list) { int curYear = cur.get(Calendar.YEAR); if (!years.contains(curYear)) { years.add(curYear);/*w ww . j av a2 s . com*/ for (Integer yearDay : mByYearDayList) { if (yearDay > 0) cur.set(Calendar.DAY_OF_YEAR, yearDay); else { cur.set(Calendar.DAY_OF_YEAR, 1); cur.roll(Calendar.DAY_OF_YEAR, yearDay); } toRet.add((Calendar) (cur.clone())); } } // year already seen? } return toRet; }
From source file:de.ribeiro.android.gso.dataclasses.Pager.java
/** * Fgt die Page an die richtige Position im pager an * * @param currentDay//w w w . j a v a 2 s . com * @param page * @param header * @param startIndex * @param stopIndex * @author Tobias Janssen */ private void insertDayPage(Calendar currentDay, View page, String header, int startIndex, int stopIndex) { // prfen, an welche stelle die page gehrt // dazu die mitte aller bestehenden pages nehmen int midPos = ((stopIndex - startIndex) / 2) + startIndex; if (midPos == 0) { // es existiert keiner, oder max ein eintrag // daher prfen, ob ein eintrag besteht if (pageIndex.size() >= 1) { // ja, einen eintrag gibt es bereits int pageDate = calcIntYearDay(pageIndex.get(midPos)); int currentDate = calcIntYearDay(currentDay); // prfen, ob die bestehende seite "lter" als die // hinzuzufgende ist if (pageDate < currentDate) { // die page indexieren pageIndex.add(midPos + 1, (Calendar) currentDay.clone()); pages.add(midPos + 1, page); headlines.add(midPos + 1, header); } else { // die page indexieren pageIndex.add(midPos, (Calendar) currentDay.clone()); pages.add(midPos, page); headlines.add(midPos, header); } } else { // nein es ist alles leer, daher einfach einfgen // die page indexieren pageIndex.add(midPos, (Calendar) currentDay.clone()); pages.add(midPos, page); headlines.add(midPos, header); } } else { // daten Tag des Jahres abrufen int pageDate = calcIntYearDay(pageIndex.get(midPos)); int currentDate = calcIntYearDay(currentDay); // prfen, ob die bestehende seite "lter" als die hinzuzufgende // ist if (pageDate < currentDate) { // ja, ist lter, daher muss die page auf jeden fall dahinder // eingefgt werden // prfen, ob direkte nachbarschaft besteht // dazu erstmal prfen, ob der nchste nachbar berhaupt // existiert if (midPos + 1 >= pageIndex.size()) { // existiert gar keiner mehr; daher page hinzufgen // die page indexieren pageIndex.add(midPos + 1, (Calendar) currentDay.clone()); pages.add(midPos + 1, page); headlines.add(midPos + 1, header); } else { // es ist ein nachbar vorhanden // prfen, ob dieser nher dran liegt als die currentPage int pageNeighborDate = calcIntYearDay(pageIndex.get(midPos + 1)); if (pageNeighborDate < currentDate) { // ja alte page ist ein nherer nachbar insertDayPage(currentDay, page, header, midPos, stopIndex); } else { // nein, currentPage ist nher // also dazwischen einfgen // die page indexieren pageIndex.add(midPos + 1, (Calendar) currentDay.clone()); pages.add(midPos + 1, page); headlines.add(midPos + 1, header); } } } else { // nein,die bestehende seite ist hat ein jngers Datum als die // hinzuzufgende, daher muss die neue page auf jeden fall davor // eingefgt werden if (midPos == 0) { // existiert gar kein eintrag; daher page hinzufgen // die page indexieren pageIndex.add((Calendar) currentDay.clone()); pages.add(page); headlines.add(header); } else { // prfen, ob der vorgnger Nachbar kleiner ist int pageNeighborDate = calcIntYearDay(pageIndex.get(midPos - 1)); if (pageNeighborDate < currentDate) { // ja davorige page ist kleiner // also dazwischen einfgen // die page indexieren pageIndex.add(midPos, (Calendar) currentDay.clone()); pages.add(midPos, page); headlines.add(midPos, header); } else { insertDayPage(currentDay, page, header, 0, midPos); } } } } }
From source file:de.ribeiro.android.gso.dataclasses.Pager.java
/** * Fgt die Page an die richtige Position im pager an * * @param currentWeek// w w w . j a v a 2s .c o m * @param page * @param header * @param startIndex * @param stopIndex * @author Tobias Janssen */ private void insertWeekPage(Calendar currentWeek, View page, String header, int startIndex, int stopIndex) { // prfen, an welche stelle die page gehrt // dazu die mitte aller bestehenden pages nehmen int midPos = ((stopIndex - startIndex) / 2) + startIndex; if (midPos == 0) { // es existiert keiner, oder max ein eintrag // daher prfen, ob ein eintrag besteht if (pageIndex.size() >= 1) { // ja, einen eintrag gibt es bereits int pageDate = calcIntYearDay(pageIndex.get(midPos)); int currentDate = calcIntYearDay(currentWeek); // prfen, ob die bestehende seite "lter" als die // hinzuzufgende ist if (pageDate < currentDate) { // die page indexieren pageIndex.add(midPos + 1, (Calendar) currentWeek.clone()); pages.add(midPos + 1, page); headlines.add(midPos + 1, header); } else { // die page indexieren pageIndex.add(midPos, (Calendar) currentWeek.clone()); pages.add(midPos, page); headlines.add(midPos, header); } } else { // nein es ist alles leer, daher einfach einfgen // die page indexieren pageIndex.add(midPos, (Calendar) currentWeek.clone()); pages.add(midPos, page); headlines.add(midPos, header); } } else { int pageDate = calcIntYearDay(pageIndex.get(midPos)); int currentDate = calcIntYearDay(currentWeek); // prfen, ob die bestehende seite "lter" als die hinzuzufgende // ist if (pageDate < currentDate) { // ja, ist lter, daher muss die page auf jeden fall dahinder // eingefgt werden // prfen, ob direkte nachbarschaft besteht // dazu erstmal prfen, ob der nchste nachbar berhaupt // existiert if (midPos + 1 >= pageIndex.size()) { // existiert gar keiner mehr; daher page hinzufgen // die page indexieren pageIndex.add(midPos + 1, (Calendar) currentWeek.clone()); pages.add(midPos + 1, page); headlines.add(midPos + 1, header); } else { // es ist ein nachbar vorhanden int pageNeighborDate = calcIntYearDay(pageIndex.get(midPos + 1)); // prfen, ob dieser nher dran liegt als die currentPage if (pageNeighborDate < currentDate) { // ja alte page ist ein nherer nachbar insertWeekPage(currentWeek, page, header, midPos, stopIndex); } else { // nein, currentPage ist nher // also dazwischen einfgen // die page indexieren pageIndex.add(midPos + 1, (Calendar) currentWeek.clone()); pages.add(midPos + 1, page); headlines.add(midPos + 1, header); } } } else { // nein,die bestehende seite ist hat ein jngers Datum als die // hinzuzufgende, daher muss die neue page auf jeden fall davor // eingefgt werden if (midPos == 0) { // existiert gar kein eintrag; daher page hinzufgen // die page indexieren pageIndex.add((Calendar) currentWeek.clone()); pages.add(page); headlines.add(header); } else { // prfen, ob der vorgnger Nachbar kleiner ist int pageNeighborDate = calcIntYearDay(pageIndex.get(midPos - 1)); if (pageNeighborDate < currentDate) { // ja davorige page ist kleiner // also dazwischen einfgen // die page indexieren pageIndex.add(midPos, (Calendar) currentWeek.clone()); pages.add(midPos, page); headlines.add(midPos, header); } else { insertWeekPage(currentWeek, page, header, 0, midPos); } } } } }
From source file:fr.paris.lutece.plugins.calendar.web.CalendarApp.java
/** * Get the XPage for getting the search result * @param request {@link HttpServletRequest} * @param plugin {@link Plugin}//from w w w .j a v a 2s . co m * @return the html * @throws SiteMessageException message if error */ private XPage getSearchResultPage(HttpServletRequest request, Plugin plugin) throws SiteMessageException { String strQuery = request.getParameter(Constants.PARAMETER_QUERY); String[] arrayCategory = request.getParameterValues(Constants.PARAMETER_CATEGORY); String[] arrayCalendar = request.getParameterValues(Constants.PARAMETER_CALENDAR_ID); String strDateBegin = request.getParameter(Constants.PARAMETER_DATE_START); String strDateEnd = request.getParameter(Constants.PARAMETER_DATE_END); String strPeriod = request.getParameter(Constants.PARAMETER_PERIOD); if (StringUtils.isBlank(strPeriod) || !StringUtils.isNumeric(strPeriod)) { strPeriod = Integer.toString(Constants.PROPERTY_PERIOD_NONE); } String strAgenda = null; String strBaseUrl = AppPathService.getBaseUrl(request); UrlItem url = new UrlItem(JSP_PAGE_PORTAL); url.addParameter(Constants.PARAMETER_QUERY, strQuery == null ? Constants.EMPTY_STRING : strQuery); url.addParameter(Constants.PARAMETER_PAGE, Constants.PLUGIN_NAME); url.addParameter(Constants.PARAMETER_ACTION, Constants.ACTION_DO_SEARCH); if (arrayCalendar != null) { for (String strAgendaId : arrayCalendar) { url.addParameter(Constants.PARAMETER_CALENDAR_ID, strAgendaId); } } else { arrayCalendar = Utils.getCalendarIds(request); } url.addParameter(Constants.PARAMETER_DATE_START, strDateBegin); url.addParameter(Constants.PARAMETER_DATE_END, strDateEnd); url.addParameter(Constants.PARAMETER_PERIOD, strPeriod); List<Event> listEvent = null; Date dateBegin = null; Date dateEnd = null; switch (Integer.parseInt(strPeriod)) { case Constants.PROPERTY_PERIOD_NONE: break; case Constants.PROPERTY_PERIOD_TODAY: dateBegin = new Date(); dateEnd = new Date(); strDateBegin = DateUtil.getDateString(new Date(), request.getLocale()); strDateEnd = DateUtil.getDateString(new Date(), request.getLocale()); break; case Constants.PROPERTY_PERIOD_WEEK: Calendar calendar = new GregorianCalendar(); Calendar calendarFirstDay = new GregorianCalendar(); Calendar calendarLastDay = new GregorianCalendar(); int nDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); if (nDayOfWeek == 1) { nDayOfWeek = 8; } calendarFirstDay = calendar; calendarFirstDay.add(Calendar.DATE, Calendar.MONDAY - nDayOfWeek); calendarLastDay = (GregorianCalendar) calendarFirstDay.clone(); calendarLastDay.add(Calendar.DATE, 6); dateBegin = calendarFirstDay.getTime(); dateEnd = calendarLastDay.getTime(); strDateBegin = DateUtil.getDateString(dateBegin, request.getLocale()); strDateEnd = DateUtil.getDateString(dateEnd, request.getLocale()); break; case Constants.PROPERTY_PERIOD_RANGE: if (StringUtils.isNotBlank(strDateBegin) && StringUtils.isNotBlank(strDateEnd)) { dateBegin = DateUtil.formatDate(strDateBegin, request.getLocale()); dateEnd = DateUtil.formatDate(strDateEnd, request.getLocale()); if (dateBegin == null || !Utils.isValidDate(dateBegin) || dateEnd == null || !Utils.isValidDate(dateEnd)) { errorDateFormat(request); } } else { errorDateFormat(request); } break; default: break; } listEvent = CalendarSearchService.getInstance().getSearchResults(arrayCalendar, arrayCategory, strQuery, dateBegin, dateEnd, plugin); _strCurrentPageIndex = Paginator.getPageIndex(request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex); _nItemsPerPage = Paginator.getItemsPerPage(request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage, _nDefaultItemsPerPage); if (listEvent == null) { listEvent = new ArrayList<Event>(); } Map<String, Object> model = new HashMap<String, Object>(); Paginator<Event> paginator = new Paginator<Event>(listEvent, _nItemsPerPage, url.getUrl(), Constants.PARAMETER_PAGE_INDEX, _strCurrentPageIndex); //if one calendar is selected if ((arrayCalendar != null) && (arrayCalendar.length == 1)) { strAgenda = arrayCalendar[0]; } UrlItem urlSubscription = new UrlItem(strBaseUrl + JSP_PAGE_PORTAL); urlSubscription.addParameter(Constants.PARAMETER_PAGE, Constants.PLUGIN_NAME); urlSubscription.addParameter(Constants.PARAMETER_ACTION, Constants.ACTION_GET_SUBSCRIPTION_PAGE); urlSubscription.addParameter(Constants.PARAM_AGENDA, strAgenda); UrlItem urlDownload = new UrlItem(strBaseUrl + JSP_PAGE_PORTAL); urlDownload.addParameter(Constants.PARAMETER_PAGE, Constants.PLUGIN_NAME); urlDownload.addParameter(Constants.PARAMETER_ACTION, Constants.ACTION_GET_DOWNLOAD_PAGE); UrlItem urlRss = new UrlItem(strBaseUrl + JSP_PAGE_RSS); urlRss.addParameter(Constants.PARAMETER_ACTION, Constants.ACTION_RSS); if (arrayCalendar != null) { for (String strAgendaId : arrayCalendar) { urlRss.addParameter(Constants.PARAMETER_CALENDAR_ID, strAgendaId); } } if (arrayCategory != null) { for (String strCategoryId : arrayCategory) { urlRss.addParameter(Constants.PARAMETER_CATEGORY, strCategoryId); } } ReferenceList listAgendas = getListAgenda(request, plugin); if (arrayCalendar != null) { listAgendas.checkItems(arrayCalendar); } Collection<Category> categoryList = _categoryService.getCategories(plugin); ReferenceList listCategorys = getReferenceListCategory(categoryList); if (arrayCategory != null) { listCategorys.checkItems(arrayCategory); } // Evol List occurrences List<List<OccurrenceEvent>> listOccurrences = new ArrayList<List<OccurrenceEvent>>(); for (Event event : listEvent) { List<OccurrenceEvent> listOccurrence = _eventListService.getOccurrenceEvents(event.getIdCalendar(), event.getId(), Constants.SORT_ASC, plugin); listOccurrences.add(listOccurrence); } CalendarUserOptions options = getUserOptions(request); options.setShowSearchEngine(Boolean.TRUE); boolean bIsSelectedDay = false; String strDate; if (StringUtils.isNotBlank(strDateBegin) && !Constants.NULL.equals(strDateBegin)) { strDate = Utils.getDate(DateUtil.formatDateLongYear(strDateBegin, request.getLocale())); if (strDateBegin.equals(strDateEnd)) { bIsSelectedDay = true; } } else { strDate = Utils.getDate(new Date()); } MultiAgenda agendaWithOccurences = _calendarService.getMultiAgenda(request); model.put(Constants.MARK_QUERY, (StringUtils.isNotBlank(strQuery)) ? strQuery : StringUtils.EMPTY); model.put(Constants.MARK_SUBSCRIPTION_PAGE, urlSubscription.getUrl()); model.put(Constants.MARK_DOWNLOAD_PAGE, urlDownload.getUrl()); model.put(Constants.MARK_RSS_PAGE, urlRss.getUrl()); model.put(Constants.MARK_DATE_START, (StringUtils.isNotBlank(strDateBegin)) ? strDateBegin : StringUtils.EMPTY); model.put(Constants.MARK_DATE_END, (StringUtils.isNotBlank(strDateEnd)) ? strDateEnd : StringUtils.EMPTY); model.put(Constants.MARK_PERIOD, (StringUtils.isNotBlank(strPeriod)) ? strPeriod : StringUtils.EMPTY); model.put(Constants.MARK_EVENTS_LIST, paginator.getPageItems()); model.put(Constants.MARK_PAGINATOR, paginator); model.put(Constants.MARK_NB_ITEMS_PER_PAGE, Integer.toString(_nItemsPerPage)); model.put(Constants.MARK_CALENDARS_LIST, listAgendas); model.put(Constants.MARK_AGENDA, (StringUtils.isNotBlank(strAgenda)) ? strAgenda : StringUtils.EMPTY); model.put(Constants.MARK_LOCALE, request.getLocale()); model.put(Constants.MARK_CATEGORY_LIST, listCategorys); model.put(Constants.MARK_OCCURRENCES_LIST, listOccurrences); model.put(Constants.MARK_SMALL_MONTH_CALENDAR, SmallMonthCalendar.getSmallMonthCalendar(strDate, agendaWithOccurences, options, bIsSelectedDay)); HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_DO_SEARCH_EVENTS, request.getLocale(), model); XPage page = new XPage(); page.setContent(template.getHtml()); page.setTitle( I18nService.getLocalizedString(Constants.PROPERTY_PAGE_TITLE_SEARCH_RESULT, request.getLocale())); page.setPathLabel( I18nService.getLocalizedString(Constants.PROPERTY_PAGE_TITLE_SEARCH, request.getLocale())); return page; }
From source file:DateFormatUtils.java
/** * <p>Formats a <code>Calendar</code> object into the * supplied <code>StringBuffer</code>.</p> * // w ww . ja v a2 s . c om * @param calendar the calendar to format * @param buf the buffer to format into * @return the specified string buffer */ public StringBuffer format(Calendar calendar, StringBuffer buf) { if (mTimeZoneForced) { calendar = (Calendar) calendar.clone(); calendar.setTimeZone(mTimeZone); } return applyRules(calendar, buf); }
From source file:com.ecofactor.qa.automation.newapp.service.MockDataServiceImpl.java
/** * Gets the sT events./*w w w .ja v a 2 s.c o m*/ * * @param thermostatId * the thermostat id * @param startTime * the start time * @param endTime * the end time * @return the sT events */ private List<PartitionedThermostatEvent> getSTEvents(Integer thermostatId, Calendar startTime, Calendar endTime) { List<PartitionedThermostatEvent> events = new ArrayList<PartitionedThermostatEvent>(); int i = 0; while (startTime.before(endTime)) { startTime.add(Calendar.MINUTE, 4); Algorithm algorithm = new Algorithm(); if (mode.equals("Cool")) { algorithm.setId(ST3_COOL); } else if (mode.equals("Heat")) { algorithm.setId(ST3_HEAT); } PartitionedThermostatEvent thermostatEvent = new PartitionedThermostatEvent(); thermostatEvent.setAlgorithmId(algorithm.getId()); thermostatEvent.setThermostatId(thermostatId); thermostatEvent.setPhase(i); thermostatEvent.getId().setEventSysTime((Calendar) startTime.clone()); thermostatEvent.setDeltaEE((double) i); thermostatEvent.setOldSetting(baseTemp); if (mode.equals("Cool")) { thermostatEvent.setNewSetting(baseTemp + i); } else if (mode.equals("Heat")) { thermostatEvent.setNewSetting(baseTemp - i); } thermostatEvent.setStatus(1); events.add(thermostatEvent); i = i + 1; i = i % 3; } return events; }
From source file:com.wdullaer.materialdatetimepicker.date.DatePickerDialog.java
private void setToNearestDate(Calendar calendar) { if (!selectableDays.isEmpty()) { Calendar newCalendar = null; Calendar higher = selectableDays.ceiling(calendar); Calendar lower = selectableDays.lower(calendar); if (higher == null && lower != null) newCalendar = lower;//from ww w . ja v a 2 s . co m else if (lower == null && higher != null) newCalendar = higher; if (newCalendar != null || higher == null) { newCalendar = newCalendar == null ? calendar : newCalendar; newCalendar.setTimeZone(getTimeZone()); calendar.setTimeInMillis(newCalendar.getTimeInMillis()); return; } long highDistance = Math.abs(higher.getTimeInMillis() - calendar.getTimeInMillis()); long lowDistance = Math.abs(calendar.getTimeInMillis() - lower.getTimeInMillis()); if (lowDistance < highDistance) calendar.setTimeInMillis(lower.getTimeInMillis()); else calendar.setTimeInMillis(higher.getTimeInMillis()); return; } if (!disabledDays.isEmpty()) { Calendar forwardDate = (Calendar) calendar.clone(); Calendar backwardDate = (Calendar) calendar.clone(); while (isDisabled(forwardDate) && isDisabled(backwardDate)) { forwardDate.add(Calendar.DAY_OF_MONTH, 1); backwardDate.add(Calendar.DAY_OF_MONTH, -1); } if (!isDisabled(backwardDate)) { calendar.setTimeInMillis(backwardDate.getTimeInMillis()); return; } if (!isDisabled(forwardDate)) { calendar.setTimeInMillis(forwardDate.getTimeInMillis()); return; } } if (isBeforeMin(calendar)) { calendar.setTimeInMillis(mMinDate.getTimeInMillis()); return; } if (isAfterMax(calendar)) { calendar.setTimeInMillis(mMaxDate.getTimeInMillis()); return; } }
From source file:com.square.core.service.implementations.PersonnePhysiqueServiceImplementation.java
/** * Calcule l'ge d'une personne partir de sa date de naissance. * @param datedeNaissance la date de naissance de la personne. * @return l'age de la personne/*w ww . j a va 2 s. c o m*/ */ private int calculerAge(Calendar datedeNaissance) { final Calendar dateNaissanceClonee = (Calendar) datedeNaissance.clone(); final Calendar dateActuelle = Calendar.getInstance(); int age = dateActuelle.get(Calendar.YEAR) - dateNaissanceClonee.get(Calendar.YEAR); dateNaissanceClonee.add(Calendar.YEAR, age); if (dateActuelle.before(dateNaissanceClonee)) { age--; } return age; }
From source file:org.kuali.ole.module.purap.document.web.struts.PurchaseOrderAction.java
/** * Sets up the PO document for Quote processing. * * @param mapping An ActionMapping/* ww w. j a va 2s . c o m*/ * @param form An ActionForm * @param request The HttpServletRequest * @param response The HttpServletResponse * @return An ActionForward * @throws Exception */ public ActionForward initiateQuote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class); PurchaseOrderForm poForm = (PurchaseOrderForm) form; PurchaseOrderDocument document = (PurchaseOrderDocument) poForm.getDocument(); if (!PurchaseOrderStatuses.APPDOC_IN_PROCESS.equals(document.getApplicationDocumentStatus())) { // PO must be "in process" in order to initiate a quote GlobalVariables.getMessageMap().putError(PurapPropertyConstants.VENDOR_QUOTES, PurapKeyConstants.ERROR_PURCHASE_ORDER_QUOTE_NOT_IN_PROCESS); return mapping.findForward(OLEConstants.MAPPING_BASIC); } Calendar currentCalendar = dateTimeService.getCurrentCalendar(); Date currentSqlDate = new java.sql.Date(currentCalendar.getTimeInMillis()); document.setPurchaseOrderQuoteInitializationDate(currentSqlDate); document.updateAndSaveAppDocStatus(PurchaseOrderStatuses.APPDOC_QUOTE); document.setStatusChange(PurchaseOrderStatuses.APPDOC_QUOTE); //TODO this needs to be done better, and probably make it a parameter Calendar expCalendar = (Calendar) currentCalendar.clone(); expCalendar.add(Calendar.DAY_OF_MONTH, 10); java.sql.Date expDate = new java.sql.Date(expCalendar.getTimeInMillis()); document.setPurchaseOrderQuoteDueDate(expDate); document.getPurchaseOrderVendorQuotes().clear(); SpringContext.getBean(PurapService.class).saveDocumentNoValidation(document); return mapping.findForward(OLEConstants.MAPPING_BASIC); }
From source file:nl.strohalm.cyclos.services.transactions.PaymentServiceImpl.java
@Override public void purgeOldTraceNumbers(final Calendar time) { Calendar c = (Calendar) time.clone(); c.add(Calendar.DAY_OF_MONTH, -1); traceNumberDao.delete(c);//from ww w .j a v a2 s . com }