Example usage for java.util Date before

List of usage examples for java.util Date before

Introduction

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

Prototype

public boolean before(Date when) 

Source Link

Document

Tests if this date is before the specified date.

Usage

From source file:com.qcadoo.mes.cmmsMachineParts.states.MaintenanceEventStateValidationService.java

private Optional<Integer> getProgressTime(Entity event) {
    StringBuilder hqlForStart = new StringBuilder();
    hqlForStart/*from w ww . j av a  2s. c o m*/
            .append("select max(dateAndTime) as date from #cmmsMachineParts_maintenanceEventStateChange sc ");
    hqlForStart.append("where sc.maintenanceEvent = :eventId and sc.status = '03successful' ");
    hqlForStart.append("and sc.targetState = '02inProgress'");
    SearchQueryBuilder query = dataDefinitionService
            .get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER,
                    CmmsMachinePartsConstants.MODEL_MAINTENANCE_EVENT_STATE_CHANGE)
            .find(hqlForStart.toString());
    query.setLong("eventId", event.getId());
    Date start = query.setMaxResults(1).uniqueResult().getDateField("date");

    StringBuilder hqlForEnd = new StringBuilder();
    hqlForEnd.append("select max(dateAndTime) as date from #cmmsMachineParts_maintenanceEventStateChange sc ");
    hqlForEnd.append("where sc.maintenanceEvent = :eventId and sc.status = '03successful' ");
    hqlForEnd.append("and sc.targetState = '03edited'");
    query = dataDefinitionService.get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER,
            CmmsMachinePartsConstants.MODEL_MAINTENANCE_EVENT_STATE_CHANGE).find(hqlForEnd.toString());
    query.setLong("eventId", event.getId());

    Date end = query.setMaxResults(1).uniqueResult().getDateField("date");

    if (start != null && end != null && start.before(end)) {
        Seconds seconds = Seconds.secondsBetween(new DateTime(start), new DateTime(end));
        return Optional.of(Integer.valueOf(seconds.getSeconds()));
    }
    return Optional.empty();
}

From source file:com.groupon.odo.bmp.BrowserMobProxyHandler.java

private SslRelayOdo getSslRelayOrCreateNewOdo(URI uri, InetAddrPort addrPort, HttpServer server)
        throws Exception {
    URI realURI = requestOriginalURI.get();
    InetAddrPort realPort = new InetAddrPort(realURI.toString());
    LOG.info("GETSSLRELAY: {}, {}", realURI, realPort);
    String host = new URL("https://" + realURI.toString()).getHost();

    // create a host and port string so the listener sslMap can be keyed off the combination
    String hostAndPort = host.concat(String.valueOf(realPort.getPort()));
    LOG.info("getSSLRelay host: {}", hostAndPort);
    SslRelayOdo listener = null;//from   w w  w  .j a v  a2s . c  o m

    synchronized (_sslMap) {
        listener = _sslMap.get(hostAndPort);
        // check the certificate expiration to see if we need to reload it
        if (listener != null) {
            Date exprDate = _certExpirationMap.get(hostAndPort);
            if (exprDate.before(new Date())) {
                // destroy the listener
                if (listener.getHttpServer() != null && listener.isStarted()) {
                    listener.getHttpServer().removeListener(listener);
                }
                listener = null;
            }
        }

        // create the listener if it didn't exist
        if (listener == null) {
            listener = new SslRelayOdo(addrPort);
            listener.setNukeDirOrFile(null);

            _certExpirationMap.put(hostAndPort, wireUpSslWithCyberVilliansCAOdo(host, listener).getNotAfter());

            listener.setPassword("password");
            listener.setKeyPassword("password");

            if (!listener.isStarted()) {
                server.addListener(listener);

                startRelayWithPortTollerance(server, listener, 1);
            }

            _sslMap.put(hostAndPort, listener);
        }
    }
    return listener;
}

From source file:org.auraframework.integration.test.http.AuraServletHttpTest.java

/**
 * Submit a request and check that the 'no cache' is set correctly.
 *
 * We are very generous with the expires time here, as we really don't care other than to have it well in the past.
 *
 * @param url the url path.//from  w ww.ja  va  2 s . c  o m
 */
private void assertResponseSetToNoCache(String url) throws Exception {
    Date expected = new Date(System.currentTimeMillis());
    HttpGet get = obtainGetMethod(url);
    HttpResponse response = perform(get);
    assertEquals("Failed to execute request successfully.", HttpStatus.SC_OK, getStatusCode(response));

    assertEquals("Expected response to be marked for no-cache", "no-cache, no-store",
            response.getFirstHeader(HttpHeaders.CACHE_CONTROL).getValue());
    assertEquals("no-cache", response.getFirstHeader(HttpHeaders.PRAGMA).getValue());
    assertDefaultAntiClickjacking(response, true, false);

    String expiresHdr = response.getFirstHeader(HttpHeaders.EXPIRES).getValue();
    Date expires = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH).parse(expiresHdr);
    //
    // We show all of the related dates/strings to help with debugging.
    //
    assertTrue(String.format("Expires header should be in the past. Expected before %s, got %s (%s).", expected,
            expires, expiresHdr), expires.before(expected));

    EntityUtils.consume(response.getEntity());
    get.releaseConnection();
}

From source file:gov.utah.dts.sdc.actions.ThirdPartyStudentAction.java

public String generateRoadTest() throws Exception {
    log.debug("generateRoadTest");
    int start = decodeTime(getRoadTestStartTime());
    Date startDate = new Date(getRoadTestCompletionDate().getTime() + start);
    log.debug("startDate " + startDate.toString());

    int end = decodeTime(getRoadTestEndTime());
    Date endDate = new Date(getRoadTestCompletionDate().getTime() + end);
    log.debug("endDate " + endDate.toString());

    if (endDate.before(startDate)) {
        addActionError("Start Time Must Be Before End Time");
        return INPUT;
    }/*from   w  ww .j  a va  2s .  c  o  m*/

    String retVal = createStudent();
    if (retVal.equals(SUCCESS)) {
        log.debug("return the jasper report");
        insertRoadAuditDate(getRoadMap(startDate, endDate));
        getSession().put(Constants.Report_WrittenCompletionStudent, getStudent());
        return GENERATE_REPORT;
    } else if (retVal.equals(Constants.EDITSTUDENT)) {
        log.debug("Existing Student Jasper report");
        getSession().put(Constants.Report_WrittenCompletionStudent, getStudent());
        return GENERATE_REPORT;
    }
    return INPUT;
}

From source file:org.auraframework.integration.test.http.AuraServletHttpTest.java

/**
 * Submit a request and check that the 'long cache' is set correctly.
 *
 * See documentation for {@link #WIGGLE_FACTOR}.
 *
 * @param url the url/*from   ww  w  .  j  a  v a 2 s  .  c  om*/
 */
private void assertResponseSetToLongCache(String url) throws Exception {
    Date expected = new Date(System.currentTimeMillis() + AuraBaseServlet.LONG_EXPIRE - WIGGLE_FACTOR);

    HttpGet get = obtainGetMethod(url);
    HttpResponse response = perform(get);

    assertEquals("Failed to execute request successfully.", HttpStatus.SC_OK, getStatusCode(response));

    assertEquals("Expected response to be marked for long cache",
            String.format("max-age=%s, public", AuraBaseServlet.LONG_EXPIRE / 1000),
            response.getFirstHeader(HttpHeaders.CACHE_CONTROL).getValue());
    assertDefaultAntiClickjacking(response, true, false);
    String expiresHdr = response.getFirstHeader(HttpHeaders.EXPIRES).getValue();
    Date expires = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH).parse(expiresHdr);
    //
    // We show all of the related dates/strings to help with debugging.
    //
    assertTrue(String.format("Expires header is earlier than expected. Expected !before %s, got %s (%s).",
            expected, expires, expiresHdr), !expires.before(expected));

    get.releaseConnection();
}

From source file:com.salesmanager.core.module.impl.application.prices.MonthlyPriceModule.java

public OrderTotalSummary calculateOrderPrice(Order order, OrderTotalSummary orderSummary,
        OrderProduct orderProduct, OrderProductPrice productPrice, String currency, Locale locale) {

    /**//from  w w  w  . j  av a 2 s.c  o m
     * Monthly price goes in the oneTime fees as well as in the upcoming
     * recursive fees
     */

    BigDecimal finalPrice = null;
    BigDecimal discountPrice = null;

    BigDecimal originalPrice = orderProduct.getOriginalProductPrice();
    if (!productPrice.isDefaultPrice()) {
        originalPrice = productPrice.getProductPriceAmount();
    }

    int quantity = orderProduct.getProductQuantity();

    // the real price is the price submited
    finalPrice = orderProduct.getProductPrice();
    finalPrice = finalPrice.multiply(new BigDecimal(quantity));

    // the final price is the product price * quantity

    if (finalPrice == null) {// pick it from the productPrice
        finalPrice = productPrice.getProductPriceAmount();
        finalPrice = finalPrice.multiply(new BigDecimal(quantity));
    }

    // this type of price needs an upfront payment
    BigDecimal otprice = orderSummary.getOneTimeSubTotal();
    if (otprice == null) {
        otprice = new BigDecimal(0);
    }

    otprice = otprice.add(finalPrice);
    orderSummary.setOneTimeSubTotal(otprice);

    ProductPriceSpecial pps = productPrice.getSpecial();

    // Build text
    StringBuffer notes = new StringBuffer();
    notes.append(quantity).append(" x ");
    notes.append(orderProduct.getProductName());
    notes.append(" ");
    if (!productPrice.isDefaultPrice()) {
        notes.append(
                CurrencyUtil.displayFormatedAmountWithCurrency(productPrice.getProductPriceAmount(), currency));
    } else {
        notes.append(CurrencyUtil.displayFormatedAmountWithCurrency(orderProduct.getProductPrice(), currency));
    }
    notes.append(" ");
    notes.append(this.getPriceSuffixText(currency, locale));

    if (pps != null) {
        if (pps.getProductPriceSpecialStartDate() != null && pps.getProductPriceSpecialEndDate() != null) {
            if (pps.getProductPriceSpecialStartDate().before(order.getDatePurchased())
                    && pps.getProductPriceSpecialEndDate().after(order.getDatePurchased())) {

                BigDecimal dPrice = new BigDecimal(ProductUtil.determinePrice(productPrice).floatValue());

                BigDecimal subTotal = originalPrice.multiply(new BigDecimal(orderProduct.getProductQuantity()));
                BigDecimal creditSubTotal = pps.getProductPriceSpecialAmount()
                        .multiply(new BigDecimal(orderProduct.getProductQuantity()));
                BigDecimal credit = subTotal.subtract(creditSubTotal);

                if (dPrice.floatValue() < productPrice.getProductPriceAmount().floatValue()) {

                    discountPrice = productPrice.getProductPriceAmount().subtract(dPrice);

                    BigDecimal newPrice = orderProduct.getProductPrice();

                    if (!productPrice.isDefaultPrice()) {
                        newPrice = productPrice.getProductPriceAmount();
                    } else {
                        newPrice = newPrice.add(discountPrice);
                    }

                    StringBuffer spacialNote = new StringBuffer();
                    spacialNote.append("<font color=\"red\">[");
                    spacialNote.append(orderProduct.getProductName());
                    spacialNote.append(" ");
                    spacialNote.append(CurrencyUtil.displayFormatedAmountWithCurrency(credit, currency));
                    spacialNote.append(" ");
                    spacialNote.append(LabelUtil.getInstance().getText(locale, "label.generic.rebate"));
                    spacialNote.append(" ");
                    spacialNote.append(LabelUtil.getInstance().getText(locale, "label.generic.until"));

                    spacialNote.append(" ");
                    spacialNote.append(DateUtil.formatDate(pps.getProductPriceSpecialEndDate()));
                    spacialNote.append("]</font>");

                    OrderTotalLine line = new OrderTotalLine();
                    // BigDecimal credit = discountPrice;
                    line.setText(spacialNote.toString());
                    line.setCost(credit);
                    line.setCostFormated(CurrencyUtil.displayFormatedAmountWithCurrency(credit, currency));
                    orderSummary.addDueNowCredits(line);
                    orderSummary.addRecursiveCredits(line);

                    BigDecimal oneTimeCredit = orderProduct.getApplicableCreditOneTimeCharge();
                    oneTimeCredit = oneTimeCredit.add(credit);
                    orderProduct.setApplicableCreditOneTimeCharge(oneTimeCredit);

                }

            } else if (pps.getProductPriceSpecialDurationDays() > -1) {

                Date dt = new Date(new Date().getTime());

                int numDays = pps.getProductPriceSpecialDurationDays();
                Date purchased = order.getDatePurchased();
                Calendar c = Calendar.getInstance();
                c.setTime(dt);
                c.add(Calendar.DATE, numDays);

                BigDecimal dPrice = new BigDecimal(ProductUtil.determinePrice(productPrice).floatValue());

                if (dt.before(c.getTime())
                        && dPrice.floatValue() < productPrice.getProductPriceAmount().floatValue()) {

                    discountPrice = productPrice.getProductPriceAmount().subtract(dPrice);

                    BigDecimal newPrice = orderProduct.getProductPrice();

                    BigDecimal subTotal = originalPrice
                            .multiply(new BigDecimal(orderProduct.getProductQuantity()));
                    BigDecimal creditSubTotal = pps.getProductPriceSpecialAmount()
                            .multiply(new BigDecimal(orderProduct.getProductQuantity()));
                    BigDecimal credit = subTotal.subtract(creditSubTotal);

                    if (!productPrice.isDefaultPrice()) {
                        newPrice = productPrice.getProductPriceAmount();
                    } else {
                        newPrice = newPrice.add(discountPrice);
                    }

                    StringBuffer spacialNote = new StringBuffer();

                    spacialNote.append("<font color=\"red\">[");
                    spacialNote.append(orderProduct.getProductName());
                    spacialNote.append(" ");
                    spacialNote.append(CurrencyUtil.displayFormatedAmountWithCurrency(credit, currency));
                    spacialNote.append(" ");
                    spacialNote.append(LabelUtil.getInstance().getText(locale, "label.generic.rebate"));
                    spacialNote.append(" ");
                    spacialNote.append(LabelUtil.getInstance().getText(locale, "label.generic.until"));

                    spacialNote.append(" ");
                    spacialNote.append(DateUtil.formatDate(c.getTime()));
                    spacialNote.append("]</font>");

                    OrderTotalLine line = new OrderTotalLine();

                    line.setText(spacialNote.toString());
                    line.setCost(credit);
                    line.setCostFormated(CurrencyUtil.displayFormatedAmountWithCurrency(credit, currency));
                    orderSummary.addDueNowCredits(line);
                    if (numDays > 30) {
                        orderSummary.addRecursiveCredits(line);
                    }

                    BigDecimal oneTimeCredit = orderProduct.getApplicableCreditOneTimeCharge();
                    oneTimeCredit = oneTimeCredit.add(credit);
                    orderProduct.setApplicableCreditOneTimeCharge(oneTimeCredit);

                    // }

                }

            }

        }

    }

    BigDecimal newPrice = orderProduct.getProductPrice();
    if (!productPrice.isDefaultPrice()) {
        newPrice = productPrice.getProductPriceAmount();
    }

    newPrice = newPrice.multiply(new BigDecimal(quantity));

    // Recursive sub total
    BigDecimal rprice = orderSummary.getRecursiveSubTotal();
    if (rprice == null) {
        rprice = new BigDecimal(0);
    }

    // recursive always contain full price
    rprice = rprice.add(newPrice);
    orderSummary.setRecursiveSubTotal(rprice);

    // recursive price
    OrderTotalLine scl = new OrderTotalLine();
    scl.setText(notes.toString());
    scl.setCost(newPrice);
    scl.setCostFormated(CurrencyUtil.displayFormatedAmountWithCurrency(newPrice, currency));
    orderSummary.addRecursivePrice(scl);

    return orderSummary;

}

From source file:com.salesmanager.core.util.ProductUtil.java

public static Date getDiscountEndDate(ProductPrice productPrice) {
    Date dt = new Date();
    BigDecimal price = productPrice.getProductPriceAmount();
    ProductPriceSpecial ppspecial = productPrice.getSpecial();
    if (ppspecial != null) {
        // this type of discount supercedes
        if (ppspecial.getProductPriceSpecialStartDate() != null
                && ppspecial.getProductPriceSpecialEndDate() != null) {
            if (ppspecial.getProductPriceSpecialStartDate().before(new Date(dt.getTime()))
                    && ppspecial.getProductPriceSpecialEndDate().after(new Date(dt.getTime()))) {

                return ppspecial.getProductPriceSpecialEndDate();

            } else if (ppspecial.getProductPriceSpecialDurationDays() > -1) {

                Date startDate = ppspecial.getProductPriceSpecialStartDate();

                int numDays = ppspecial.getProductPriceSpecialDurationDays();
                Date purchased = new Date();
                Calendar c = Calendar.getInstance();
                c.setTime(dt);/*from  w w w.  j av  a  2 s .  c o  m*/
                c.add(Calendar.DATE, numDays);

                if (dt.before(c.getTime()) && ppspecial.getProductPriceSpecialAmount()
                        .floatValue() < productPrice.getProductPriceAmount().floatValue()) {
                    return c.getTime();
                } else {
                    return null;
                }
            }

        }
    }
    return null;
}

From source file:com.virtusa.akura.reporting.controller.PerDayStaffCategoryWiseAttendanceController.java

/**
 * get present staff list with half day leave reason if any.
 *
 * @param presentStaffList - present staff list
 * @param dateConsider - date of the report .
 * @return map of staff/* w w w. j  a v  a2 s  .c  om*/
 * @throws AkuraAppException throw exception if occur.
 */
private Map<Staff, String> getPresentStaffListWithLeaveReason(List<Staff> presentStaffList, Date dateConsider)
        throws AkuraAppException {

    // create an present map for staffs with half day leave reason.

    Map<Staff, String> presentMap = new LinkedHashMap<Staff, String>();
    // Map<Staff, String> presentMap = new TreeMap<Staff, String>();
    Date attDate = dateConsider;

    if (!presentStaffList.isEmpty()) {

        for (Staff staff : presentStaffList) {
            String leaveDayType = null;
            List<StaffLeave> staffLeaveList = staffService.getStaffLeaveListByDatePeriodAndStaffId(attDate,
                    attDate, staff.getStaffId());

            if (!staffLeaveList.isEmpty()) {

                for (StaffLeave sl : staffLeaveList) {

                    Date getFromDate = DateUtil.getParseDate(sl.getFromDate().toString());
                    Date getToDate = DateUtil.getParseDate(sl.getToDate().toString());

                    if (getFromDate.before(attDate) && getToDate.after(attDate)) {

                        if (sl.getStaffLeaveStatusId().intValue() == 1) {
                            leaveDayType = sl.getDateType();
                        }

                    } else if (getFromDate.equals(attDate) || getToDate.equals(attDate)) {
                        if (sl.getStaffLeaveStatusId().intValue() == 1) {
                            leaveDayType = sl.getDateType();
                        }
                    }
                }
            }

            presentMap.put(staff, leaveDayType);

        }

    }
    return presentMap;

}

From source file:com.salesmanager.core.util.ProductUtil.java

public static boolean hasDiscount(ProductPrice productPrice) {
    Date dt = new Date();
    BigDecimal price = productPrice.getProductPriceAmount();
    ProductPriceSpecial ppspecial = productPrice.getSpecial();
    if (ppspecial != null) {
        // this type of discount supercedes
        if (ppspecial.getProductPriceSpecialStartDate() != null
                && ppspecial.getProductPriceSpecialEndDate() != null) {
            if (ppspecial.getProductPriceSpecialStartDate().before(new Date(dt.getTime()))
                    && ppspecial.getProductPriceSpecialEndDate().after(new Date(dt.getTime()))) {

                return true;

            } else if (ppspecial.getProductPriceSpecialDurationDays() > -1) {

                Date startDate = ppspecial.getProductPriceSpecialStartDate();

                int numDays = ppspecial.getProductPriceSpecialDurationDays();
                Date purchased = new Date();
                Calendar c = Calendar.getInstance();
                c.setTime(dt);//from w w w.  java 2 s.  c o  m
                c.add(Calendar.DATE, numDays);
                // if(dt.before(c.getTime())) {

                if (dt.before(c.getTime()) && ppspecial.getProductPriceSpecialAmount()
                        .floatValue() < productPrice.getProductPriceAmount().floatValue()) {
                    return true;
                } else {
                    return false;
                }
            }

        }
    }
    return false;
}

From source file:com.virtusa.akura.reporting.controller.GenarateTeacherWisePresentAndAbsentDaysReportController.java

/**
 * Check the given date is a holiday or not.
 *
 * @param holidayList - list consits of Holidays for the given time period.
 * @param currentDate - currentDate//from w  ww  .  j a va2s .c  o m
 * @param start - Calender object
 * @return boolean
 */
public boolean isHoliday(List<Holiday> holidayList, Date currentDate, Calendar start) {

    boolean flag = false;
    int dayOfWeek = start.get(Calendar.DAY_OF_WEEK);

    for (Holiday tempHoliday : holidayList) {
        if ((currentDate.after(tempHoliday.getStartDate()) && currentDate.before(tempHoliday.getEndDate()))
                || currentDate.equals(tempHoliday.getStartDate())
                || currentDate.equals(tempHoliday.getEndDate()) || Calendar.SATURDAY == dayOfWeek
                || Calendar.SUNDAY == dayOfWeek) {

            flag = true;
            break;
        }
    }
    return flag;
}