List of usage examples for java.util Date after
public boolean after(Date when)
From source file:com.google.sampling.experiential.server.EventRetriever.java
private void sortList(ArrayList<Event> newArrayList) { Comparator<Event> dateComparator = new Comparator<Event>() { @Override//from w w w . j a va 2s.c o m public int compare(Event o1, Event o2) { Date when1 = o1.getWhen(); Date when2 = o2.getWhen(); if (when1 == null || when2 == null) { return 0; } else if (when1.after(when2)) { return -1; } else if (when2.after(when1)) { return 1; } return 0; } }; Collections.sort(newArrayList, dateComparator); }
From source file:fr.paris.lutece.plugins.calendar.business.portlet.MiniCalendarPortlet.java
/** * Returns the Xml code of the Calendar portlet without XML heading * /*from ww w . j av a 2s .c o m*/ * @param request The HTTP servlet request * @return the Xml code of the Archive portlet content */ public String getXml(HttpServletRequest request) { StringBuffer strXml = new StringBuffer(); Locale locale = null; if (_cal == null) { _cal = new GregorianCalendar(); } if (request != null) { locale = request.getLocale(); if ((request.getParameter(Constants.PARAMETER_MONTH) != null) && (request.getParameter(Constants.PARAMETER_MONTH)).equals(Constants.PARAMETER_NEXT)) { _cal.add(Calendar.MONTH, 1); } else if ((request.getParameter(Constants.PARAMETER_MONTH) != null) && (request.getParameter(Constants.PARAMETER_MONTH)).equals(Constants.PARAMETER_PREV)) { _cal.add(Calendar.MONTH, -1); } XmlUtil.addElement(strXml, TAG_URL, AppPathService.getBaseUrl(request) + JSP_PORTAL_URL + POINT_INTERROGATION + PARAM_PAGE_ID + EGAL); } else { locale = I18nService.getDefaultLocale(); } //Load the xml calendar strXml.append(XMLUtils.getXMLPortletCalendar(locale, _cal, request)); //Top event section Plugin plugin = PluginService.getPlugin(Constants.PLUGIN_NAME); boolean topevent = MiniCalendarPortletHome.showTopEvent(); if (topevent) { XmlUtil.beginElement(strXml, TAG_TOP_EVENTS); List<SimpleEvent> listEvents = CalendarHome.findTopEventList(plugin); Iterator<SimpleEvent> i = listEvents.iterator(); while (i.hasNext()) { XmlUtil.beginElement(strXml, TAG_TOP_EVENT); SimpleEvent event = i.next(); XmlUtil.addElement(strXml, TAG_TOP_EVENT_TITLE, (event.getTitle() != null) ? event.getTitle() : ""); XmlUtil.addElement(strXml, TAG_EVENT_ID, event.getId()); XmlUtil.addElement(strXml, TAG_AGENDA_ID, event.getIdCalendar()); XmlUtil.endElement(strXml, TAG_TOP_EVENT); //Register the image EventImageResourceService.getInstance().getResourceImageEvent(event.getId()); } XmlUtil.endElement(strXml, TAG_TOP_EVENTS); } String strDateBegin = request != null ? request.getParameter(Constants.PARAMETER_DATE) : StringUtils.EMPTY; // If there is no date begin in the parameter, then get today's date if (StringUtils.isBlank(strDateBegin)) { strDateBegin = DateUtil.getCurrentDateString(locale); } String[] arrayCategory = null; String[] arrayCalendar = Utils.getCalendarIds(request); String strQuery = StringUtils.EMPTY; List<Event> listEvent = null; Plugin pluginCalendar = PluginService.getPlugin(CalendarPlugin.PLUGIN_NAME); Date dateBegin = DateUtil.formatDate(strDateBegin, request != null ? request.getLocale() : Locale.getDefault()); // If there is a date end, then it is a search on a date interval String strDateEnd = request != null ? request.getParameter(Constants.PARAMETER_DATE_END) : StringUtils.EMPTY; Date dateEnd = null; if (StringUtils.isNotBlank(strDateEnd)) { dateEnd = DateUtil.formatDate(strDateEnd, request != null ? request.getLocale() : Locale.getDefault()); } if (dateEnd == null) { dateEnd = dateBegin; } listEvent = CalendarSearchService.getInstance().getSearchResults(arrayCalendar, arrayCategory, strQuery, dateBegin, dateEnd, pluginCalendar); if (listEvent != null) { //Sort events by DateTimeStart using bubble sort SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); boolean bisModification; Date date1; Date date2; Event temporaryEvent; do { bisModification = true; for (int j = 0; j < listEvent.size() - 1; j++) { try { date1 = sdf.parse(listEvent.get(j).getDateTimeStart()); } catch (Exception e) { date1 = new Date(0); } try { date2 = sdf.parse(listEvent.get(j + 1).getDateTimeStart()); } catch (Exception e) { date2 = new Date(0); } if (date1.after(date2)) { temporaryEvent = listEvent.get(j + 1); listEvent.set(j + 1, listEvent.get(j)); listEvent.set(j, temporaryEvent); bisModification = false; } } } while (!bisModification); XmlUtil.beginElement(strXml, TAG_EVENTS); for (Event event : listEvent) { XmlUtil.beginElement(strXml, TAG_EVENT); // Search on date interval, then display date begin and date end if (StringUtils.isNotBlank(strDateEnd) && !strDateBegin.equals(strDateEnd)) { XmlUtil.addElement(strXml, TAG_DATE, DateUtil.getDateString(event.getDate(), locale)); XmlUtil.addElement(strXml, TAG_DATE_END, DateUtil.getDateString(event.getDateEnd(), locale)); } // Else only display the date on which the user has clicked else { XmlUtil.addElement(strXml, TAG_DATE, strDateBegin); XmlUtil.addElement(strXml, TAG_DATE_END, StringUtils.EMPTY); } XmlUtil.addElementHtml(strXml, TAG_EVENT_TITLE, (event.getTitle() != null) ? event.getTitle() : StringUtils.EMPTY); XmlUtil.addElement(strXml, TAG_EVENT_DATETIME_BEGIN, (event.getDateTimeStart() != null) ? event.getDateTimeStart() : StringUtils.EMPTY); XmlUtil.addElementHtml(strXml, TAG_EVENT_DESCRIPTION, (event.getDescription() != null) ? event.getDescription() : StringUtils.EMPTY); XmlUtil.addElement(strXml, TAG_EVENT_ID, event.getId()); XmlUtil.endElement(strXml, TAG_EVENT); } XmlUtil.endElement(strXml, TAG_EVENTS); } String str = addPortletTags(strXml); return str; }
From source file:com.aimluck.eip.msgboard.MsgboardTopicSelectData.java
/** * ResultData ??????? <BR>/*from w w w .ja va2 s .co m*/ * * @param obj * @return */ @Override protected Object getResultData(EipTMsgboardTopic record) { try { MsgboardTopicResultData rd = new MsgboardTopicResultData(); rd.initField(); rd.setTopicId(record.getTopicId().longValue()); rd.setTopicName(record.getTopicName()); rd.setCategoryId(record.getEipTMsgboardCategory().getCategoryId().longValue()); rd.setCategoryName(record.getEipTMsgboardCategory().getCategoryName()); // /?? rd.setPublicFlag("T".equals(record.getEipTMsgboardCategory().getPublicFlag())); rd.setOwnerId(record.getOwnerId().longValue()); rd.setOwnerName(ALEipUtils.getUserFullName(record.getOwnerId().intValue())); rd.setUpdateUser(ALEipUtils.getUserFullName(record.getUpdateUserId().intValue())); rd.setUpdateDate(record.getUpdateDate()); // ?????? 1 Date date = record.getUpdateDate(); Calendar now = Calendar.getInstance(); now.add(Calendar.DATE, -1); rd.setNewTopicFlag(date.after(now.getTime())); rd.setReplyCount(MsgboardUtils.countReply(record.getTopicId())); rd.setLoginUserId(uid); return rd; } catch (Exception ex) { logger.error("msgboard", ex); return null; } }
From source file:com.nec.harvest.controller.SuisController.java
private boolean availableNext(String orgCode, int currentQuater, Date currentYear, Model model, Date finalTighten, Date businessDay) { final String URL_NEXT = "nextUrl"; try {// ww w .ja v a2 s. c o m // if quarter equal 4 then set quarter equal 1 int intNextQuater = currentQuater + 1; if (currentQuater == 5) { intNextQuater = 1; } // get three month of next quarter String[] monthiesNext = DateUtil.getMonthliesOfQuarter(currentYear, intNextQuater); String nextQuarter = null; Date firstDate = DateFormatUtil.parse(monthiesNext[0], DateFormat.DATE_WITHOUT_DAY); if (firstDate.after(businessDay)) { // next url set null <=> disabled button next model.addAttribute(URL_NEXT, nextQuarter); return true; } // greater than tighten date if (firstDate.after(finalTighten)) { // count data in v_jiseki view if count greater > 0 then return true otherwise return false if (actualViewService.checkAvailableByOrgCodeAndMonthly(orgCode, monthiesNext)) { nextQuarter = DateUtil.nextQuarter(firstDate); } } else { // count data in budget performance if count greater > 0 then return true otherwise return false boolean isNextAvailable = budgetPerformanceService.checkAvailableByOrgCodeAndMonthlyAndKmkCodeJs( orgCode, monthiesNext[0], Constants.DEFAULT_KMKCODEJ_K7111, Constants.DEFAULT_KMKCODEJ_K7521, Constants.DEFAULT_KMKCODEJ_K8110, Constants.DEFAULT_KMKCODEJ_K8210, Constants.DEFAULT_KMKCODEJ_K8310); if (isNextAvailable) { nextQuarter = DateUtil.nextQuarter(firstDate); } } model.addAttribute(URL_NEXT, nextQuarter); } catch (IllegalArgumentException | NullPointerException | ParseException ex) { logger.warn(ex.getMessage()); // model.addAttribute(URL_NEXT, null); } catch (ServiceException ex) { logger.error(ex.getMessage(), ex); // ??????????? model.addAttribute(ERROR_MESSAGE, getSystemError()); model.addAttribute(ERROR, true); return false; } return true; }
From source file:org.openmrs.module.appointmentscheduling.api.impl.AppointmentServiceImpl.java
@Override @Transactional(readOnly = false)/*www . j a v a 2 s . co m*/ public List<Appointment> cleanOpenAppointments() { List<AppointmentStatus> states = new LinkedList<AppointmentStatus>(); states.add(AppointmentStatus.SCHEDULED); states.add(AppointmentStatus.WAITING); states.add(AppointmentStatus.WALKIN); states.add(AppointmentStatus.INCONSULTATION); List<Appointment> appointmentsInStates = appointmentDAO.getPastAppointmentsByStates(states); if (appointmentsInStates == null) return new LinkedList<Appointment>(); Iterator<Appointment> iter = appointmentsInStates.iterator(); Date now = Calendar.getInstance().getTime(); while (iter.hasNext()) { Appointment appointment = iter.next(); //Check if past appointment if (now.after(appointment.getTimeSlot().getEndDate())) { AppointmentStatus status = appointment.getStatus(); switch (status) { case SCHEDULED: case WAITING: case WALKIN: changeAppointmentStatus(appointment, AppointmentStatus.MISSED); break; case INCONSULTATION: changeAppointmentStatus(appointment, AppointmentStatus.COMPLETED); break; default: //No need to change appointmentsInStates.remove(appointment); break; } } else { appointmentsInStates.remove(appointment); } } return appointmentsInStates; }
From source file:View.DialogoEstadisticas.java
private boolean combrobarIntervalo(String periodo) { if (intervalo) { String fechaI = null;//from w w w.ja va2 s .c om String fechaF = null; String periodoI = null; String periodoF = null; SimpleDateFormat dt1 = new SimpleDateFormat("dd-MM-yyyy"); StringTokenizer st = new StringTokenizer(periodo, "/"); while (st.hasMoreTokens()) { fechaI = st.nextToken(); fechaF = st.nextToken(); } st = new StringTokenizer(fechaIntervaloI, "/"); periodoI = st.nextToken(); st = new StringTokenizer(fechaIntervaloF, "/"); while (st.hasMoreTokens()) { st.nextToken(); periodoF = st.nextToken(); } try { Date dI = dt1.parse(fechaI); Date dF = dt1.parse(fechaF); Date dIntevaloI = dt1.parse(periodoI); Date dIntevaloF = dt1.parse(periodoF); return (dI.after(dIntevaloI) && dF.before(dIntevaloF)) || (dI.compareTo(dIntevaloI) == 0) || (dF.compareTo(dIntevaloF) == 0); } catch (ParseException ex) { Logger.getLogger(DialogoEstadisticas.class.getName()).log(Level.SEVERE, null, ex); return false; } } else { return true; } }
From source file:com.nec.harvest.controller.SuisController.java
private boolean availablePrevious(String orgCode, int currentQuater, Date currentYear, Model model, Date finalTighten) {/*from w ww. j ava 2 s . c o m*/ final String URL_PREVIOUS = "previousUrl"; try { // if quarter equal 1 then set quarter equal 4 int preQuater = currentQuater - 1; if (currentQuater == 0) { preQuater = 4; } // get three month of previous quarter String[] monthiesPrevious = DateUtil.getMonthliesOfQuarter(currentYear, preQuater); String previousQuarter = null; Date date = DateFormatUtil.parse(monthiesPrevious[2], DateFormat.DATE_WITHOUT_DAY); // greater than tighten date if (date.after(finalTighten)) { if (actualViewService.checkAvailableByOrgCodeAndMonthly(orgCode, monthiesPrevious)) { previousQuarter = DateUtil.previousQuarter(date); } } else { boolean isPreviousAvailable = budgetPerformanceService .checkAvailableByOrgCodeAndMonthlyAndKmkCodeJs(orgCode, monthiesPrevious[2], Constants.DEFAULT_KMKCODEJ_K7111, Constants.DEFAULT_KMKCODEJ_K7521, Constants.DEFAULT_KMKCODEJ_K8110, Constants.DEFAULT_KMKCODEJ_K8210, Constants.DEFAULT_KMKCODEJ_K8310); if (isPreviousAvailable) { previousQuarter = DateUtil.nextQuarter(date); } } model.addAttribute(URL_PREVIOUS, previousQuarter); } catch (IllegalArgumentException | NullPointerException | ParseException | ObjectNotFoundException ex) { logger.warn(ex.getMessage()); // set value url previous and disable previous button model.addAttribute(URL_PREVIOUS, null); } catch (ServiceException ex) { logger.error(ex.getMessage(), ex); // ??????????? model.addAttribute(ERROR_MESSAGE, getSystemError()); model.addAttribute(ERROR, true); return false; } return true; }
From source file:com.labimo.portlet.LicenseManage.java
@ProcessAction(name = "updateLicense") public void updateLicense(ActionRequest actionRequest, ActionResponse response) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat(liferay_pattern); User currentUser = PortalUtil.getUser(actionRequest); Utils utils = new Utils(); long userId = ParamUtil.getLong(actionRequest, "userId"); String licenseUuid = ParamUtil.getString(actionRequest, "licenseUuid"); licenseUuid = LicenseUtils.formatToString(licenseUuid); String hardwareUuid = ParamUtil.getString(actionRequest, "hardwareUuid"); Boolean valid = ParamUtil.getBoolean(actionRequest, "valid"); Date issueDate = ParamUtil.getDate(actionRequest, "issueDate", sdf); Date validDate = ParamUtil.getDate(actionRequest, "validDate", sdf); long currentTime = new Date().getTime(); System.out.println("userId = " + userId); System.out.println("licenseUuid = " + licenseUuid); System.out.println("issueDate = " + issueDate); System.out.println("hardwareUuid = " + hardwareUuid); System.out.println("validDate = " + validDate); System.out.println("valid = " + valid + " valid=" + ParamUtil.getString(actionRequest, "valid")); License license = LicenseLocalServiceUtil.getLicense(licenseUuid); if (license != null && license.getUserId() == userId && validDate.after(issueDate) && validDate.getTime() > currentTime) { System.out.println("======"); license.setModifiedDate(new Date()); license.setIssueDate(issueDate); license.setValidDate(validDate); license.setValid(valid);/*from w w w . j av a 2 s . com*/ LicenseLocalServiceUtil.updateLicense(license); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long gourpId = themeDisplay.getScopeGroupId(); JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(); extraDataJSONObject.put("title", currentUser.getScreenName() + LicenseConstants.UPDATE_LICENSE_MSG + license.getLicenseUuid()); SocialActivityLocalServiceUtil.addActivity(currentUser.getUserId(), gourpId, LicenseConstants.LICENSE_CLASS_NAME, LicenseConstants.LICENSE_CLASS_NAME_ID, LicenseConstants.UPDATE_LICENSE, extraDataJSONObject.toString(), 0); } }
From source file:com.emc.ecs.sync.target.S3Target.java
@Override public void filter(SyncObject obj) { try {/*from w ww . j ava 2 s. c o m*/ // skip the root of the bucket since it obviously exists if ("".equals(rootKey + obj.getRelativePath())) { log.debug("Target is bucket root; skipping"); return; } // some sync objects lazy-load their metadata (i.e. AtmosSyncObject) // since this may be a timed operation, ensure it loads outside of other timed operations if (!(obj instanceof S3ObjectVersion) || !((S3ObjectVersion) obj).isDeleteMarker()) obj.getMetadata(); // Compute target key String targetKey = getTargetKey(obj); obj.setTargetIdentifier(AwsS3Util.fullPath(bucketName, targetKey)); if (includeVersions) { ListIterator<S3ObjectVersion> sourceVersions = s3Source.versionIterator((S3SyncObject) obj); ListIterator<S3ObjectVersion> targetVersions = versionIterator(obj); boolean newVersions = false, replaceVersions = false; if (force) { replaceVersions = true; } else { // special workaround for bug where objects are listed, but they have no versions if (sourceVersions.hasNext()) { // check count and etag/delete-marker to compare version chain while (sourceVersions.hasNext()) { S3ObjectVersion sourceVersion = sourceVersions.next(); if (targetVersions.hasNext()) { S3ObjectVersion targetVersion = targetVersions.next(); if (sourceVersion.isDeleteMarker()) { if (!targetVersion.isDeleteMarker()) replaceVersions = true; } else { if (targetVersion.isDeleteMarker()) replaceVersions = true; else if (!sourceVersion.getETag().equals(targetVersion.getETag())) replaceVersions = true; // different checksum } } else if (!replaceVersions) { // source has new versions, but existing target versions are ok newVersions = true; sourceVersions.previous(); // back up one putIntermediateVersions(sourceVersions, targetKey); // add any new intermediary versions (current is added below) } } if (targetVersions.hasNext()) replaceVersions = true; // target has more versions if (!newVersions && !replaceVersions) { log.info("Source and target versions are the same. Skipping {}", obj.getRelativePath()); return; } } } // something's off; must delete all versions of the object if (replaceVersions) { log.info( "[{}]: version history differs between source and target; re-placing target version history with that from source.", obj.getRelativePath()); // collect versions in target List<DeleteObjectsRequest.KeyVersion> deleteVersions = new ArrayList<>(); while (targetVersions.hasNext()) targetVersions.next(); // move cursor to end while (targetVersions.hasPrevious()) { // go in reverse order S3ObjectVersion version = targetVersions.previous(); deleteVersions.add(new DeleteObjectsRequest.KeyVersion(targetKey, version.getVersionId())); } // batch delete all versions in target log.debug("[{}]: deleting all versions in target", obj.getRelativePath()); s3.deleteObjects(new DeleteObjectsRequest(bucketName).withKeys(deleteVersions)); // replay version history in target while (sourceVersions.hasPrevious()) sourceVersions.previous(); // move cursor to beginning putIntermediateVersions(sourceVersions, targetKey); } } else { // normal sync (no versions) Date sourceLastModified = obj.getMetadata().getModificationTime(); long sourceSize = obj.getMetadata().getContentLength(); // Get target metadata. ObjectMetadata destMeta = null; try { destMeta = s3.getObjectMetadata(bucketName, targetKey); } catch (AmazonS3Exception e) { if (e.getStatusCode() != 404) throw new RuntimeException("Failed to check target key '" + targetKey + "' : " + e, e); } if (!force && obj.getFailureCount() == 0 && destMeta != null) { // Check overwrite Date destLastModified = destMeta.getLastModified(); long destSize = destMeta.getContentLength(); if (destLastModified.equals(sourceLastModified) && sourceSize == destSize) { log.info("Source and target the same. Skipping {}", obj.getRelativePath()); return; } if (destLastModified.after(sourceLastModified)) { log.info("Target newer than source. Skipping {}", obj.getRelativePath()); return; } } } // at this point we know we are going to write the object // Put [current object version] if (obj instanceof S3ObjectVersion && ((S3ObjectVersion) obj).isDeleteMarker()) { // object has version history, but is currently deleted log.debug("[{}]: deleting object in target to replicate delete marker in source.", obj.getRelativePath()); s3.deleteObject(bucketName, targetKey); } else { putObject(obj, targetKey); // if object has new metadata after the stream (i.e. encryption checksum), we must update S3 again if (obj.requiresPostStreamMetadataUpdate()) { log.debug("[{}]: updating metadata after sync as required", obj.getRelativePath()); CopyObjectRequest cReq = new CopyObjectRequest(bucketName, targetKey, bucketName, targetKey); cReq.setNewObjectMetadata(AwsS3Util.s3MetaFromSyncMeta(obj.getMetadata())); s3.copyObject(cReq); } } } catch (Exception e) { throw new RuntimeException("Failed to store object: " + e, e); } }
From source file:com.stimulus.archiva.domain.Volume.java
public boolean isDateValid(Email email) { Date sentDate = null; try {/*from ww w .j a v a2 s. c o m*/ sentDate = email.getSentDate(); } catch (Exception e) { } // there is no sent date if (sentDate == null) return false; // sent date should never be after archive date if (sentDate.after(email.getArchiveDate())) return false; Date receivedDate = email.getReceivedDate(); if (receivedDate != null) { // we add 30 minutes to account for minute time differentials Calendar marginCal = Calendar.getInstance(); marginCal.setTime(receivedDate); marginCal.add(Calendar.MINUTE, 30); // sent date cannot be after received date if (sentDate.after(marginCal.getTime())) { return false; } /* // if the received date is available, sent date cannot be older than received date - 7 days Calendar oldCal = Calendar.getInstance(); String oldOut = oldCal.getTime().toString(); oldCal.setTime(receivedDate); oldCal.add(Calendar.DATE, -7); String newOut = oldCal.getTime().toString(); System.out.println("receiveDate:"+receivedDate); System.out.println("oldOut:"+oldOut); System.out.println("newOut:"+newOut); System.out.println("sentDate:"+sentDate); Date oldDate = oldCal.getTime(); if (sentDate.before(oldDate)) { return false; }*/ } return true; }