List of usage examples for java.util Calendar before
public boolean before(Object when)
Calendar
represents a time before the time represented by the specified Object
. From source file:org.videolan.vlc.gui.TimePickerDialogFragment.java
@Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { if (!setTime) { //workaround for weird ICS&JB bug setTime = true;// w w w. j av a 2 s . c om return; } Calendar currentTime = Calendar.getInstance(); Calendar sleepTime = Calendar.getInstance(); sleepTime.set(Calendar.HOUR_OF_DAY, hourOfDay); sleepTime.set(Calendar.MINUTE, minute); sleepTime.set(Calendar.SECOND, 0); switch (action) { case ACTION_SLEEP: if (sleepTime.before(currentTime)) sleepTime.roll(Calendar.DATE, true); AdvOptionsDialog.setSleep(view.getContext(), sleepTime); break; case ACTION_JUMP: long time = (long) ((hourOfDay * 60 + minute) * 60000); LibVLC.getExistingInstance().setTime(time); break; } }
From source file:org.videolan.vlc.gui.dialogs.TimePickerDialogFragment.java
@Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { if (!setTime) { //workaround for weird ICS&JB bug setTime = true;/* ww w. j a v a 2s. c om*/ return; } Calendar currentTime = Calendar.getInstance(); Calendar sleepTime = Calendar.getInstance(); sleepTime.set(Calendar.HOUR_OF_DAY, hourOfDay); sleepTime.set(Calendar.MINUTE, minute); sleepTime.set(Calendar.SECOND, 0); switch (action) { case ACTION_SLEEP: if (sleepTime.before(currentTime)) sleepTime.add(Calendar.DATE, 1); AdvOptionsDialog.setSleep(sleepTime); break; case ACTION_JUMP: long time = (hourOfDay * 60l + minute) * 60000l; final MediaPlayer mediaPlayer = VLCInstance.getMainMediaPlayer(); mediaPlayer.setTime(time); break; } }
From source file:com.adobe.acs.commons.http.headers.impl.MonthlyExpiresHeaderFilter.java
@Override protected void adjustExpires(Calendar next) { if (StringUtils.equalsIgnoreCase(LAST, dayOfMonth)) { next.set(Calendar.DAY_OF_MONTH, next.getActualMaximum(Calendar.DAY_OF_MONTH)); } else {// w ww. j a va 2s . c o m next.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dayOfMonth)); } if (next.before(Calendar.getInstance())) { next.add(Calendar.MONTH, 1); } }
From source file:de.lemo.apps.application.DateWorkerImpl.java
public int daysBetween(final Date startDate, final Date endDate) { // TODO see daysBetween(Calendar, Calendar) final Calendar startDateTemp = Calendar.getInstance(); final Calendar endDateTemp = (Calendar) startDateTemp.clone(); endDateTemp.setTime(endDate);/*from ww w . java 2s . co m*/ startDateTemp.setTime(startDate); int daysBetween = 0; while (startDateTemp.before(endDateTemp)) { startDateTemp.add(Calendar.DAY_OF_MONTH, 1); daysBetween++; } return daysBetween; }
From source file:org.kuali.kra.award.paymentreports.awardreports.reporting.service.ReportTrackingNotificationServiceImpl.java
/** * Is date1 after from and before until? * @param date1// w ww . j ava 2 s .c om * @param from * @param until * @return */ protected boolean doDatesMatch(Date date1, Calendar from, Calendar until) { Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1); clearTimeFields(cal1); return cal1.after(from) && (cal1.equals(until) || cal1.before(until)); }
From source file:me.neatmonster.spacertk.scheduler.Job.java
/** * Creates a new Job/*from w w w .j a v a 2 s .c o m*/ * @param actionName Action to preform * @param actionArguments Arguments to preform the action with * @param timeType Type of time to schedule the action with * @param timeArgument Argument of time to schedule the action with * @param loading If the job is being loaded * @throws UnSchedulableException If the action cannot be scheduled * @throws UnhandledActionException If the action is unknown */ public Job(final String actionName, final Object[] actionArguments, final String timeType, final String timeArgument, final boolean loading) throws UnSchedulableException, UnhandledActionException { if (!SpaceRTK.getInstance().actionsManager.contains(actionName)) { if (!loading) { final String result = Utilities.sendMethod("isSchedulable", "[\"" + actionName + "\"]"); if (result == null || !result.equals("true")) if (result == null || result.equals("")) throw new UnhandledActionException(); else throw new UnSchedulableException("Action " + actionName + " isn't schedulable!"); } } else if (!SpaceRTK.getInstance().actionsManager.isSchedulable(actionName)) throw new UnSchedulableException("Action " + actionName + " isn't schedulable!"); this.actionName = actionName; this.actionArguments = actionArguments; this.timeType = timeType; this.timeArgument = timeArgument; if (timeType.equals("EVERYXHOURS")) timer.scheduleAtFixedRate(this, Integer.parseInt(timeArgument) * 3600000L, Integer.parseInt(timeArgument) * 3600000L); else if (timeType.equals("EVERYXMINUTES")) timer.scheduleAtFixedRate(this, Integer.parseInt(timeArgument) * 60000L, Integer.parseInt(timeArgument) * 60000L); else if (timeType.equals("ONCEPERDAYAT")) { Calendar nextOccurence = Calendar.getInstance(); nextOccurence.set(Calendar.HOUR, Integer.parseInt(timeArgument.split(":")[0])); nextOccurence.set(Calendar.MINUTE, Integer.parseInt(timeArgument.split(":")[1])); if (nextOccurence.before(new Date())) nextOccurence = Calendar.getInstance(); nextOccurence.setTimeInMillis(nextOccurence.getTimeInMillis() + 86400000L); timer.scheduleAtFixedRate(this, nextOccurence.getTime(), 86400000L); } else if (timeType.equals("XMINUTESPASTEVERYHOUR")) { Calendar nextOccurence = Calendar.getInstance(); nextOccurence.set(Calendar.MINUTE, Integer.parseInt(timeArgument)); if (nextOccurence.before(new Date())) nextOccurence = Calendar.getInstance(); nextOccurence.setTimeInMillis(nextOccurence.getTimeInMillis() + 3600000L); timer.scheduleAtFixedRate(this, nextOccurence.getTime(), 3600000L); } Scheduler.saveJobs(); }
From source file:de.hybris.platform.acceleratorservices.web.payment.validation.PaymentDetailsValidator.java
@Override public void validate(final Object object, final Errors errors) { final PaymentDetailsForm form = (PaymentDetailsForm) object; final Calendar start = parseDate(form.getStartMonth(), form.getStartYear()); final Calendar expiration = parseDate(form.getExpiryMonth(), form.getExpiryYear()); final Calendar current = Calendar.getInstance(); if (start.after(current)) { errors.rejectValue("startMonth", "payment.startDate.past.invalid"); }//from ww w.j av a 2 s . c o m if (expiration.before(current)) { errors.rejectValue("expiryMonth", "payment.expiryDate.future.invalid"); } if (start.after(expiration)) { errors.rejectValue("startMonth", "payment.startDate.invalid"); } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.firstName", "address.firstName.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.lastName", "address.lastName.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.line1", "address.line1.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.townCity", "address.city.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.postcode", "address.postcode.invalid"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billingAddress.countryIso", "address.country.invalid"); }
From source file:fr.paris.lutece.plugins.workflow.modules.alert.service.daemon.AlertDaemon.java
/** * Daemon's treatment method//from w w w . j a va 2 s . c om */ public void run() { StringBuilder sbLog = new StringBuilder(); ITaskConfigService configService = SpringContextService.getBean(AlertConstants.BEAN_ALERT_CONFIG_SERVICE); IAlertService alertService = SpringContextService.getBean(AlertService.BEAN_SERVICE); for (Alert alert : alertService.findAll()) { Record record = alertService.getRecord(alert); TaskAlertConfig config = configService.findByPrimaryKey(alert.getIdTask()); Locale locale = I18nService.getDefaultLocale(); if (record != null && config != null) { if (alertService.isRecordStateValid(config, record, locale)) { Long lDate = alert.getDateReference().getTime(); if (lDate != null) { int nNbDaysToDate = config.getNbDaysToDate(); Calendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(lDate); calendar.add(Calendar.DATE, nNbDaysToDate); Calendar calendarToday = new GregorianCalendar(); if (calendar.before(calendarToday)) { sbLog.append("\n-Running alert (ID record : " + record.getIdRecord() + ", ID history : " + alert.getIdResourceHistory() + ", ID task : " + alert.getIdTask() + ")"); alertService.doChangeRecordState(config, record.getIdRecord(), alert); } } } } else { // If the record is null or the config is null, we remove the alert alertService.removeByHistory(alert.getIdResourceHistory(), alert.getIdTask()); } } if (StringUtils.isBlank(sbLog.toString())) { sbLog.append("\nNo alert to run."); } setLastRunLogs(sbLog.toString()); }
From source file:org.wso2.carbon.event.ws.internal.builders.SubscribeCommandBuilder.java
/** * (01) <s12:Envelope// w ww .j av a 2s .c o m * (02) xmlns:s12="http://www.w3.org/2003/05/soap-envelope" * (03) xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" * (04) xmlns:wse="http://schemas.xmlsoap.org/ws/2004/08/eventing" * (05) xmlns:ew="http://www.example.com/warnings" > * (06) <s12:Header> * (07) <wsa:Action> * (08) http://schemas.xmlsoap.org/ws/2004/08/eventing/Subscribe * (09) </wsa:Action> * (10) <wsa:MessageID> * (11) uuid:e1886c5c-5e86-48d1-8c77-fc1c28d47180 * (12) </wsa:MessageID> * (13) <wsa:ReplyTo> * (14) <wsa:Address>http://www.example.com/MyEvEntsink</wsa:Address> * (15) <wsa:ReferenceProperties> * (16) <ew:MySubscription>2597</ew:MySubscription> * (17) </wsa:ReferenceProperties> * (18) </wsa:ReplyTo> * (19) <wsa:To>http://www.example.org/oceanwatch/EventSource</wsa:To> * (20) </s12:Header> * (21) <s12:Body> * (22) <wse:Subscribe> * (23) <wse:EndTo> * (24) <wsa:Address> * (25) http://www.example.com/MyEventSink * (26) </wsa:Address> * (27) <wsa:ReferenceProperties> * (28) <ew:MySubscription>2597</ew:MySubscription> * (29) </wsa:ReferenceProperties> * (30) </wse:EndTo> * (31) <wse:Delivery> * (32) <wse:NotifyTo> * (33) <wsa:Address> * (34) http://www.other.example.com/OnStormWarning * (35) </wsa:Address> * (36) <wsa:ReferenceProperties> * (37) <ew:MySubscription>2597</ew:MySubscription> * (38) </wsa:ReferenceProperties> * (39) </wse:NotifyTo> * (40) </wse:Delivery> * (41) <wse:Expires>2004-06-26T21:07:00.000-08:00</wse:Expires> * (42) <wse:Filter xmlns:ow="http://www.example.org/oceanwatch" * (43) Dialect="http://www.example.org/topicFilter" > * (44) weather.storms * (45) </wse:Filter> * (46) </wse:Subscribe> * (47) </s12:Body> * (48) </s12:Envelope> * * @param envelope The soap envelope containing the subscription request * @return The created subscription * @throws InvalidMessageException * @throws InvalidExpirationTimeException */ public Subscription toSubscription(SOAPEnvelope envelope) throws InvalidMessageException, InvalidExpirationTimeException { Subscription subscription = null; OMElement notifyToElem; if (envelope == null) { log.error("No SOAP envelope was provided."); throw new BuilderException("No SOAP envelope was provided."); } OMElement elem = null; if (envelope.getBody() != null) { elem = envelope.getBody().getFirstChildWithName(SUBSCRIBE_QNAME); } if (elem != null) { OMElement deliveryElem = elem.getFirstChildWithName(DELIVERY_QNAME); if (deliveryElem != null) { notifyToElem = deliveryElem.getFirstChildWithName(NOTIFY_TO_QNAME); if (notifyToElem != null) { String ep = BuilderUtils.getEndpointFromWSAAddress(notifyToElem.getFirstElement()); if (ep != null) { subscription = new Subscription(); subscription.setEventSinkURL(ep); } } else { log.error("NotifyTo element not found in the subscription message."); throw new InvalidMessageException("NotifyTo element not found in the subscription message."); } } else { log.error("Delivery element is not found in the subscription message."); throw new InvalidMessageException("Delivery element is not found in the subscription message."); } OMElement filterElem = elem.getFirstChildWithName(FILTER_QNAME); if (subscription != null && filterElem != null) { OMAttribute dialectAttribute = filterElem.getAttribute(ATT_DIALECT); if (dialectAttribute != null && dialectAttribute.getAttributeValue() != null) { subscription.setEventFilter( new EventFilter(dialectAttribute.getAttributeValue(), filterElem.getText().trim())); } else { log.error("Error in creating subscription. Filter dialect not defined."); throw new BuilderException("Error in creating subscription. Filter dialect not defined."); } } else if (subscription == null) { log.error("Error in creating subscription."); throw new BuilderException("Error in creating subscription."); } OMElement expiryElem = elem.getFirstChildWithName(EXPIRES); if (expiryElem != null) { Calendar calendarExpires; try { String expiryText = expiryElem.getText().trim(); if (expiryText.startsWith("P")) { calendarExpires = Calendar.getInstance(); Duration duration = ConverterUtil.convertToDuration(expiryText); calendarExpires.add(Calendar.YEAR, duration.getYears()); calendarExpires.add(Calendar.MONTH, duration.getMonths()); calendarExpires.add(Calendar.DAY_OF_MONTH, duration.getDays()); calendarExpires.add(Calendar.HOUR_OF_DAY, duration.getHours()); calendarExpires.add(Calendar.MINUTE, duration.getMinutes()); calendarExpires.add(Calendar.SECOND, (int) duration.getSeconds()); } else { calendarExpires = ConverterUtil.convertToDateTime(expiryText); } } catch (Exception e) { log.error("Error converting the expiration date.", e); throw new InvalidExpirationTimeException("Error converting the expiration date.", e); } Calendar calendarNow = Calendar.getInstance(); if (calendarNow.before(calendarExpires)) { subscription.setExpires(calendarExpires); } else { log.error("The expiration time has passed."); throw new InvalidExpirationTimeException("The expiration time has passed."); } } OMElement scriptElement = elem .getFirstChildWithName(new QName(EventingConstants.WSE_EXTENDED_EVENTING_NS, EventingConstants.EVENTING_EXECUTABLE_SCRIPT_ELEMENT)); if (scriptElement != null) { subscription.getProperties().put(EventingConstants.EVENTING_EXECUTABLE_SCRIPT_ELEMENT, scriptElement.getText()); } } else { log.error("Subscribe element is required as the payload of the subscription message."); throw new InvalidMessageException( "Subscribe element is required as the payload of the subscription message."); } return subscription; }
From source file:fedora.server.security.servletfilters.CacheElement.java
private static final boolean isExpired(Calendar now, Calendar expiration, boolean verbose) { String m = "- isExpired() "; if (verbose) { LOG.debug(m + ">"); }/*from w w w. jav a2s . c om*/ boolean rc = CacheElement.s_expired_default; try { if (now == null) { String msg = "illegal parm now==" + now; LOG.error(m + "(" + msg + ")"); throw new IllegalArgumentException(msg); } if (expiration == null) { String msg = "illegal parm expiration==" + expiration; LOG.error(m + "(" + msg + ")"); throw new IllegalArgumentException(msg); } if (verbose) { LOG.debug(m + "now==" + format(now)); LOG.debug(m + "exp==" + format(expiration)); } rc = !now.before(expiration); } catch (Throwable th) { LOG.error(m + "failed comparison"); rc = CacheElement.s_expired_default; } finally { if (verbose) { LOG.debug(m + compareForExpiration(now, expiration)); LOG.debug(m + "< " + rc); } } return rc; }