Example usage for java.util Calendar before

List of usage examples for java.util Calendar before

Introduction

In this page you can find the example usage for java.util Calendar before.

Prototype

public boolean before(Object when) 

Source Link

Document

Returns whether this Calendar represents a time before the time represented by the specified Object.

Usage

From source file:org.kuali.kra.iacuc.onlinereview.authorization.ModifyIacucProtocolOnlineReviewDeterminationAuthorizer.java

public boolean isAuthorized(String userId, IacucProtocolOnlineReviewTask task) {
    boolean hasPermission = false;
    IacucProtocolOnlineReview protocolOnlineReview = (IacucProtocolOnlineReview) task.getProtocolOnlineReview();
    ProtocolOnlineReviewDocumentBase protocolDoc = null;
    try {/*from   w  w  w .j a v a  2s .  co m*/
        protocolDoc = (ProtocolOnlineReviewDocumentBase) KcServiceLocator.getService(DocumentService.class)
                .getByDocumentHeaderId(
                        protocolOnlineReview.getProtocolOnlineReviewDocument().getDocumentNumber());

        if (protocolOnlineReview.getProtocolOnlineReviewId() != null
                && !protocolOnlineReview.getProtocolOnlineReviewDocument().isViewOnly()) {
            if (hasPermission(userId, protocolOnlineReview, PermissionConstants.MAINTAIN_IACUC_ONLINE_REVIEWS)
                    && !protocolDoc.getDocumentHeader().getWorkflowDocument().isFinal()) {
                hasPermission = true;
            } else if (hasPermission(userId, protocolOnlineReview,
                    PermissionConstants.MAINTAIN_IACUC_PROTOCOL_ONLINE_REVIEW_COMMENTS)
                    && kraWorkflowService.isUserApprovalRequested(protocolDoc, userId)) {
                String reviewerTypeCode = protocolOnlineReview.getProtocolReviewer().getReviewerTypeCode();
                if (StringUtils.equals(reviewerTypeCode, IacucProtocolReviewerType.PRIMARY)
                        || StringUtils.equals(reviewerTypeCode, IacucProtocolReviewerType.SECONDARY)) {
                    hasPermission = true;
                } else if (StringUtils.equals(reviewerTypeCode, IacucProtocolReviewerType.COMMITTEE)) {
                    if (protocolOnlineReview.getDeterminationReviewDateDue() != null) {
                        Calendar today = Calendar.getInstance();
                        Calendar typeDueDate = Calendar.getInstance();
                        typeDueDate.setTime(protocolOnlineReview.getDeterminationReviewDateDue());
                        hasPermission = typeDueDate.before(today);
                    } else {
                        hasPermission = true;
                    }
                }
            }
        }
    } catch (WorkflowException e) {
        LOG.error(String.format("Could not find ProtocolOnlineReviewBase, document number %s",
                protocolOnlineReview.getProtocolOnlineReviewDocument().getDocumentNumber()));
    }
    return hasPermission;
}

From source file:com.bt.sdk.callcontrol.demo.standup.MapHousekeeper.java

private void housekeepConferenceFutures() {
    for (String key : conferenceFutures.keySet()) {
        // Test conference 3:1905:2008:01:07
        String[] parts = key.split(":");
        Calendar now = Calendar.getInstance();
        Calendar then = (Calendar) now.clone();
        then.set(Integer.parseInt(parts[2]), Integer.parseInt(parts[3]), Integer.parseInt(parts[4]));
        //System.out.println(now);
        //System.out.println(then);
        if (then.before(now)) {
            log.info(String.format("removing old conferenceFuture: %s", key));
            conferenceFutures.remove(key);
            keysToRemove.add(key);//from www.java2 s.  c om
        }
    }
}

From source file:org.yes.cart.web.page.component.customer.order.CustomerOrderPanel.java

private Date determineDate(final PageParameters pageParameters) {
    String viewTime = pageParameters.get("view").toString();
    if (viewTime == null || !SUPPORTED_VIEWS.contains(viewTime)) {
        viewTime = DEFAULT_VIEW;//  w  w  w  .jav  a 2  s . c  o  m
    }

    if ("all".equals(viewTime)) {
        return null;
    }

    final Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    if ("month".equals(viewTime)) {

        calendar.set(Calendar.DAY_OF_MONTH, 1);

    } else if ("year".equals(viewTime)) {

        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.MONTH, 0);

    } else {

        calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());

        final Calendar now = Calendar.getInstance();
        if (now.before(calendar)) {
            calendar.add(Calendar.DATE, -7);
        }

    }

    return calendar.getTime();
}

From source file:br.com.transport.report.ManagerReportBean.java

/**
 * Retira da lista de dias da semana os dias utilizados no frete
 * @param mapReport/*from  ww w .j a  va2  s  .  c o m*/
 * @param handlerList
 */
private void removeDays(Map<Long, List<Calendar>> mapReport, List<ReportVO> handlerList) {

    Calendar init = getInitCalendar();

    Calendar end = getInitCalendar();

    for (ReportVO report : handlerList) {

        List<Calendar> daysList = new LinkedList<Calendar>(mapReport.get(report.getCarrierId()));

        init.setTime(report.getDepartureDate());
        end.setTime(report.getDeliveryDate());

        for (Calendar cld : daysList) {
            if (cld.compareTo(init) == 0 || (cld.after(init) && (cld.before(end) || cld.compareTo(end) == 0))) {
                mapReport.get(report.getCarrierId()).remove(cld);
            }
        }
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.DateTimeIntervalValidation.java

private Map<String, String> checkDateLiterals(Literal startLit, Literal endLit,
        VitroVocabulary.Precision startPrecision, VitroVocabulary.Precision endPrecision) {
    Map<String, String> errors = new HashMap<String, String>();

    if (endPrecision == null) {
        //there is no end date, nothing to check
        return errors;
    }/*  w  w  w  . j a  va2  s.co  m*/

    try {
        XSDDateTime startDate = (XSDDateTime) startLit.getValue();
        XSDDateTime endDate = (XSDDateTime) endLit.getValue();
        if (startDate != null && endDate != null) {
            Calendar startCal = startDate.asCalendar();
            Calendar endCal = endDate.asCalendar();

            if (endCal != null) {
                if (!startCal.before(endCal)) {
                    if (startPrecision == VitroVocabulary.Precision.YEAR
                            && endPrecision == VitroVocabulary.Precision.YEAR) {
                        errors.putAll(checkYears(startCal, endCal));
                    } else {
                        errors.put(startFieldName, "Start must be before end");
                        errors.put(endFieldName, "End must be after start");
                    }
                }
            }
        }
    } catch (ClassCastException cce) {
        errors.put(startFieldName, "could not format start or end date");
        errors.put(endFieldName, "could not format start or end date");
        log.debug("could not format dates " + cce);
    }

    return errors;
}

From source file:org.apache.synapse.eventing.managers.DefaultInMemorySubscriptionManager.java

public List<Subscription> getMatchingSubscriptions(Event<MessageContext> event) throws EventException {
    final LinkedList<Subscription> list = new LinkedList<Subscription>();
    for (Map.Entry<String, Subscription> stringSubscriptionEntry : store.entrySet()) {
        //TODO : pick the filter based on the dialect
        //XPathBasedEventFilter filter = new XPathBasedEventFilter();
        TopicBasedEventFilter filter = new TopicBasedEventFilter();
        if (filter != null) {
            filter.setResultValue(stringSubscriptionEntry.getValue().getFilterValue());
            filter.setSourceXpath(topicXPath);
            //evaluatedValue = topicXPath.stringValueOf(mc);
        }//from  ww w . j  ava  2s .  c o m
        if (filter == null || filter.match(event)) {
            Subscription subscription = stringSubscriptionEntry.getValue();
            Calendar current = Calendar.getInstance(); //Get current date and time
            if (subscription.getExpires() != null) {
                if (current.before(subscription.getExpires())) {
                    // add only valid subscriptions by checking the expiration
                    list.add(subscription);
                }
            } else {
                // If a expiration dosen't exisits treat it as a never expire subscription, valid till unsubscribe
                list.add(subscription);
            }

        }
    }
    return list;
}

From source file:se.acrend.christopher.server.service.impl.BillingServiceImpl.java

public SubscriptionInfo billingCompleted(final String productId) {
    Entity subscription = subscriptionController.findSubscription();

    SubscriptionInfo result = new SubscriptionInfo();

    log.debug("Anvndare {} har kpt produkt {}.",
            new Object[] { subscription.getProperty("userEmail"), productId });
    Entity product = productDao.findByProductId(productId);
    if (product == null) {
        log.error("Hittade inte produkt med id {}", productId);
        result.setReturnCode(ReturnCode.Failure);

        return result;
    }/*from  w  w  w . ja  v  a 2s . co m*/
    ProductCategory category = ProductCategory.valueOf((String) product.getProperty("category"));
    ProductType type = ProductType.valueOf((String) product.getProperty("type"));
    String value = (String) product.getProperty("value");

    if (category == ProductCategory.Notification) {
        if (type == ProductType.Day) {
            Calendar now = DateUtil.createCalendar();
            Calendar expireDate = DateUtil.createCalendar();
            expireDate.setTime((Date) subscription.getProperty("notificationExpireDate"));

            if (expireDate.before(now)) {
                expireDate = now;
            }

            int days = Integer.parseInt(value);

            expireDate.add(Calendar.DAY_OF_YEAR, days);

            subscription.setProperty("notificationExpireDate", expireDate.getTime());
        }
        if (type == ProductType.Count) {

            int currentCount = (Integer) subscription.getProperty("notificationCount");

            int count = Integer.parseInt(value);

            subscription.setProperty("notificationCount", currentCount + count);
        }
    }

    subscriptionController.update(subscription);

    result.setNotificationCount(EntityUtil.getInt(subscription, "notificationCount", 0));
    result.setTravelWarrantCount(EntityUtil.getInt(subscription, "travelWarrantCount", 0));
    result.setNotificationExpireDate(
            DateUtil.toCalendar((Date) subscription.getProperty("notificationExpireDate")));
    result.setTravelWarrantExpireDate(
            DateUtil.toCalendar((Date) subscription.getProperty("travelWarrantExpireDate")));

    result.setReturnCode(ReturnCode.Success);

    return result;
}

From source file:org.exoplatform.services.jcr.ext.classify.impl.DateTimeClassifyPlugin.java

public void classifyChildrenNode(Node parent) throws Exception {
    Session session = parent.getSession();
    for (NodeIterator nodes = parent.getNodes(); nodes.hasNext();) {
        Node node = nodes.nextNode();
        Calendar calNode = node.getProperty(propertyDateTime).getDate();
        if ((calNode.before(startDateTime)) || (calNode.after(endDateTime)))
            continue;
        Node currentNode = createNewDateTimeNode(parent, getDateTimeStructured(templateDateTime, calNode));
        String srcPath = node.getPath();
        String destPath = currentNode.getPath() + "/" + node.getName();
        session.move(srcPath, destPath);
        session.save();//from  ww  w  .  jav a 2  s .  co m
    }
}

From source file:de.hybris.platform.acceleratorservices.web.payment.validation.SopPaymentDetailsValidator.java

@Override
public void validate(final Object object, final Errors errors) {
    final SopPaymentDetailsForm form = (SopPaymentDetailsForm) object;

    final Calendar startOfCurrentMonth = getCalendarResetTime();
    startOfCurrentMonth.set(Calendar.DAY_OF_MONTH, 1);

    final Calendar startOfNextMonth = getCalendarResetTime();
    startOfNextMonth.set(Calendar.DAY_OF_MONTH, 1);
    startOfNextMonth.add(Calendar.MONTH, 1);

    final Calendar start = parseDate(form.getCard_startMonth(), form.getCard_startYear());
    final Calendar expiration = parseDate(form.getCard_expirationMonth(), form.getCard_expirationYear());

    if (start != null && !start.before(startOfNextMonth)) {
        errors.rejectValue("card_startMonth", "payment.startDate.invalid");
    }// w w  w  . j  a v  a2  s.c  om
    if (expiration != null && expiration.before(startOfCurrentMonth)) {
        errors.rejectValue("card_expirationMonth", "payment.startDate.invalid");
    }
    if (start != null && expiration != null && start.after(expiration)) {
        errors.rejectValue("card_startMonth", "payment.startDate.invalid");
    }

    if (StringUtils.isBlank(form.getBillTo_country())) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billTo_country", "address.country.invalid");
    } else {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billTo_firstName", "address.firstName.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billTo_lastName", "address.lastName.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billTo_street1", "address.line1.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billTo_city", "address.city.invalid");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "billTo_postalCode", "address.postcode.invalid");
    }
}

From source file:DateUtil.java

/**
 * Returns true if the two calendars represent dates that fall in the same
 * week, else false. A week here is defined by the Calendar.WEEK_OF_YEAR
 * package. Special provisions have been made to test weeks than may span the
 * end/beginning of a year, and returning true if the two calendars are
 * specifying dates within such a week, despite Calendar.WEEK_OF_YEAR being
 * unequal for the two Calendars.//from www .  ja  v  a 2s . c o  m
 * 
 * @param c1
 *          Calendar one.
 * @param c2
 *          Calendar two.
 * @return boolean.
 */
public static boolean inSameWeek(Calendar c1, Calendar c2) {
    if (inSameYear(c1, c2) && (c1.get(Calendar.WEEK_OF_YEAR) == c2.get(Calendar.WEEK_OF_YEAR)))
        return true;

    Calendar tmp;
    if (c1.before(c2)) {
        tmp = c2;
        c2 = c1;
        c1 = tmp;
    }

    int c1week = c1.get(Calendar.WEEK_OF_YEAR);
    int c2week = c1.get(Calendar.WEEK_OF_YEAR);

    if (c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR) + 1) {
        if (c1week == c1.getActualMinimum(Calendar.WEEK_OF_YEAR)
                && c2week == c2.getActualMaximum(Calendar.WEEK_OF_YEAR)) {
            tmp = (Calendar) c2.clone();
            tmp.add(Calendar.DAY_OF_YEAR, 7);
            if (tmp.get(Calendar.WEEK_OF_YEAR) > c1week)
                return true;
        }
    }

    return false;
}