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.icanft.common.startup.ValidateLicense.java

/**
 * License//  ww  w.java2s .com
 * 
 * @param licenseColl LicenseColl
 * @param path String
 * @return boolean
 */
public static boolean validateLicense(LicenseColl licenseColl, String path) {
    // ??
    boolean payedUser = true;
    List<String> macAddressList = CollectMacAddress.getMacAddress();
    for (LicenseInfo licenseInfo : licenseColl.getLicenseInfoList()) {
        String productName = licenseInfo.getProductName();
        String expirationDate = licenseInfo.getExpiration();
        String signature = licenseInfo.getSignature();
        boolean flag = false;
        String data = new StringBuffer().append(productName).append(expirationDate).toString();
        java.security.cert.CertificateFactory cf;
        try {
            cf = java.security.cert.CertificateFactory.getInstance("X.509");

            java.security.cert.Certificate cert = cf
                    .generateCertificate(new FileInputStream(path + "/WEB-INF/fbrp.cer"));

            // 
            PublicKey pubKey = cert.getPublicKey();
            // ??Signature
            Signature sig = Signature.getInstance("SHA1withDSA");
            sig.initVerify(pubKey);
            sig.update(InternationalizationUtil.getBytes(data));
            // ?License
            boolean verifies = true;
            //                  sig.verify(Base64.decodeBase64(InternationalizationUtil
            //                  .getBytes(signature)));
            if (verifies) {
                Date evalDate = DateTimeUtil.parseDate(expirationDate);
                if (evalDate.before(new Date())) {
                    // ?
                    payedUser = false;
                } else {
                    flag = true;
                    payedUser = true;
                    System.out.println(
                            "" + productName + " License" + expirationDate + "?");
                }
            }
        } catch (Exception e) {
            log.error("", e);
        }

        if (!flag) {
            payedUser = false;
            System.out.println(
                    "" + productName + " License??License?");
        }
    }
    return payedUser;
}

From source file:com.mqm.frame.infrastructure.util.ValidateLicense.java

/**
 * License/*from ww w  .java2  s . c o  m*/
 * 
 * @param licenseColl LicenseColl
 * @param path String
 * @return boolean
 */
public static boolean validateLicense(LicenseColl licenseColl, String path) {
    // ??
    boolean payedUser = true;
    List<String> macAddressList = CollectMacAddress.getMacAddress();
    for (LicenseInfo licenseInfo : licenseColl.getLicenseInfoList()) {
        String productName = licenseInfo.getProductName();
        String expirationDate = licenseInfo.getExpiration();
        String signature = licenseInfo.getSignature();
        boolean flag = false;
        String data = new StringBuffer().append(productName).append(expirationDate).toString();
        java.security.cert.CertificateFactory cf;
        try {
            cf = java.security.cert.CertificateFactory.getInstance("X.509");

            java.security.cert.Certificate cert = cf
                    .generateCertificate(new FileInputStream(path + "/WEB-INF/fbrp.cer"));

            // 
            PublicKey pubKey = cert.getPublicKey();
            // ??Signature
            Signature sig = Signature.getInstance("SHA1withDSA");
            sig.initVerify(pubKey);
            sig.update(InternationalizationUtil.getBytes(data));
            // ?License
            boolean verifies = sig.verify(Base64.decode((InternationalizationUtil.getBytes(signature))));
            if (verifies) {
                Date evalDate = DateTimeUtil.parseDate(expirationDate);
                if (evalDate.before(new Date())) {
                    // ?
                    payedUser = false;
                } else {
                    flag = true;
                    payedUser = true;
                    System.out.println(
                            "" + productName + " License" + expirationDate + "?");
                }
            }
        } catch (Exception e) {
            log.error("", e);
        }

        if (!flag) {
            payedUser = false;
            System.out.println(
                    "" + productName + " License??License?");
        }
    }
    return payedUser;
}

From source file:com.qm.frame.infrastructure.util.ValidateLicense.java

/**
 * License//from w  w  w.jav  a  2s  .  c  om
 * 
 * @param licenseColl LicenseColl
 * @param path String
 * @return boolean
 */
public static boolean validateLicense(LicenseColl licenseColl, String path) {
    // ??
    boolean payedUser = true;
    List<String> macAddressList = CollectMacAddress.getMacAddress();
    for (LicenseInfo licenseInfo : licenseColl.getLicenseInfoList()) {
        String productName = licenseInfo.getProductName();
        String expirationDate = licenseInfo.getExpiration();
        String signature = licenseInfo.getSignature();
        boolean flag = false;
        String data = new StringBuffer().append(productName).append(expirationDate).toString();
        java.security.cert.CertificateFactory cf;
        try {
            cf = java.security.cert.CertificateFactory.getInstance("X.509");

            java.security.cert.Certificate cert = cf
                    .generateCertificate(new FileInputStream(path + "/WEB-INF/qm.cer"));

            // 
            PublicKey pubKey = cert.getPublicKey();
            // ??Signature
            Signature sig = Signature.getInstance("SHA1withDSA");
            sig.initVerify(pubKey);
            sig.update(InternationalizationUtil.getBytes(data));
            // ?License
            boolean verifies = sig.verify(Base64.decode((InternationalizationUtil.getBytes(signature))));
            if (verifies) {
                Date evalDate = DateTimeUtil.parseDate(expirationDate);
                if (evalDate.before(new Date())) {
                    // ?
                    payedUser = false;
                } else {
                    flag = true;
                    payedUser = true;
                    System.out.println(
                            "" + productName + " License" + expirationDate + "?");
                }
            }
        } catch (Exception e) {
            log.error("", e);
        }

        if (!flag) {
            payedUser = false;
            System.out.println(
                    "" + productName + " License??License?");
        }
    }
    return payedUser;
}

From source file:gov.nasa.arc.spife.ui.table.days.Day.java

public static boolean extentsIntersect(TemporalExtent dayExtent, TemporalExtent elementExtent) {
    Date dayStart = dayExtent.getStart();
    Date elementEnd = elementExtent.getEnd();
    if (elementEnd.before(dayStart)) {
        return false;
    }// w  w  w  .  ja v a  2s. co  m
    Date elementStart = elementExtent.getStart();
    Date dayEnd = dayExtent.getEnd();
    if (elementStart.after(dayEnd)) {
        return false;
    }
    if (elementEnd.equals(dayStart) && !elementStart.equals(dayStart)) {
        return false;
    }
    return true;
}

From source file:Main.java

public static String formatExpirationDate(String text) {

    try {/*  w  ww . ja v  a  2 s  . com*/
        switch (text.length()) {
        case 1:
            int digit = Integer.parseInt(text);

            if (digit < 2) {
                return text;
            } else {
                return "0" + text + "/";
            }
        case 2:
            int month = Integer.parseInt(text);
            if (month > 12 || month < 1) {
                // Invalid digit
                return text.substring(0, 1);
            } else {
                return text + "/";
            }
        case 3:
            if (text.substring(2, 3).equalsIgnoreCase("/")) {
                return text;
            } else {
                text = text.substring(0, 2) + "/" + text.substring(2, 3);
            }
        case 4:
            Calendar now = getCurrentExpDate();
            String year = String.valueOf(now.get(Calendar.YEAR));
            int yearDigit = Integer.parseInt(text.substring(3, 4));
            int currentYearDigit = Integer.parseInt(year.substring(2, 3));
            if (yearDigit < currentYearDigit) {
                // Less than current year invalid
                return text.substring(0, 3);
            } else {
                return text;
            }
        case 5:
            Calendar now2 = getCurrentExpDate();
            String currentYearStr2 = String.valueOf(now2.get(Calendar.YEAR));
            String yearStr = text.substring(0, 3) + currentYearStr2.substring(0, 2) + text.substring(3, 5);
            Date expiry = simpleDateFormat.parse(yearStr);
            if (expiry.before(now2.getTime())) {
                // Invalid exp date
                return text.substring(0, 4);
            } else {
                return text;
            }
        default:
            if (text.length() > 5) {
                return text.substring(0, 5);
            } else {
                return text;
            }
        }

    } catch (ParseException e) {
        e.printStackTrace();
    }
    // If an exception is thrown we clear out the text
    return "";
}

From source file:common.util.DateUtil.java

public static boolean isCurrentWeek(Date fechainicio, Date fechafin, Date date) {
    return DateUtils.isSameDay(date, fechainicio) || DateUtils.isSameDay(date, fechafin)
            || (date.after(fechainicio) && date.before(fechafin));
}

From source file:gov.nasa.arc.spife.ui.table.days.Day.java

public static boolean intersectsExtent(TemporalExtent dayExtent, Date elementStart, Date elementEnd) {
    Date dayStart = dayExtent.getStart();
    if (elementEnd.before(dayStart)) {
        return false;
    }/*from   w w w  .  j  a  va 2s .c o  m*/
    Date dayEnd = dayExtent.getEnd();
    if (elementStart.after(dayEnd)) {
        return false;
    }
    if (elementEnd.equals(dayStart) && !elementStart.equals(dayStart)) {
        return false;
    }
    return true;
}

From source file:com.vmware.identity.rest.core.server.util.VerificationUtil.java

/**
 * Verifies the request was issued within a certain amount of skew.
 *
 * @param context the request context to verify
 * @param skew the amount of skew to allow in milliseconds
 * @param log a logger to log the error to
 *
 * @return true if the request time is valid, false otherwise
 *///from   w  ww. j a va  2  s.  c om
public static boolean verifyRequestTime(ContainerRequestContext context, long skew, IDiagnosticsLogger log) {
    long currentTime = System.currentTimeMillis();
    Date beginsAt = new Date(currentTime - skew);
    Date expiresAt = new Date(currentTime + skew);

    Date requestTime = context.getDate();

    if (requestTime.before(beginsAt) || requestTime.after(expiresAt)) {
        log.error(String.format(
                "Request time outside of acceptable range. Request time: '%s'. Acceptable range: ['%s', '%s']",
                requestTime, beginsAt, expiresAt));
        return false;
    }

    return true;
}

From source file:org.toobsframework.biz.validation.CustomValidationUtils.java

/**
 * Given three integer inputs representing a date, checks to 
 * see if the specified date is after today's date.
 * @param day - int 1-31/*from w ww  .j ava 2  s.  com*/
 * @param month - int 1-12
 * @param year
 * @return
 */
public static boolean rejectIfDayMonthYearBeforeToday(Integer day, Integer month, Integer year) {
    if (day != null && month != null && year != null) {
        //construct Calendar object
        //set time fields with inputted parameters
        GregorianCalendar cal = new GregorianCalendar();
        // note month conversion: Calendar expects 0 based month param
        cal.set(year, month - 1, day);
        //get a date object out of the 
        Date closingDate = cal.getTime();

        //if the closing date is before right now,
        //then throw a validation error
        if (closingDate.before(new Date(System.currentTimeMillis()))) {
            return false;
        }
    }

    return true;
}

From source file:org.hsweb.web.service.impl.quartz.QuartzJobServiceImpl.java

public static List<Date> computeFireTimesBetween(OperableTrigger trigger, org.quartz.Calendar cal, Date from,
        Date to, int num) {
    LinkedList<Date> lst = new LinkedList<>();
    OperableTrigger t = (OperableTrigger) trigger.clone();
    if (t.getNextFireTime() == null) {
        t.setStartTime(from);/*  ww  w.  jav  a2  s . c  o  m*/
        t.setEndTime(to);
        t.computeFirstFireTime(cal);
    }
    for (int i = 0; i < num; i++) {
        Date d = t.getNextFireTime();
        if (d != null) {
            if (d.before(from)) {
                t.triggered(cal);
                continue;
            }
            if (d.after(to)) {
                break;
            }
            lst.add(d);
            t.triggered(cal);
        } else {
            break;
        }
    }
    return java.util.Collections.unmodifiableList(lst);
}