Example usage for java.util GregorianCalendar compareTo

List of usage examples for java.util GregorianCalendar compareTo

Introduction

In this page you can find the example usage for java.util GregorianCalendar compareTo.

Prototype

@Override
public int compareTo(Calendar anotherCalendar) 

Source Link

Document

Compares the time values (millisecond offsets from the Epoch) represented by two Calendar objects.

Usage

From source file:bioLockJ.AppController.java

private static File getRestartDir() throws Exception {
    File restartDir = null;//www . jav  a  2 s  . com
    GregorianCalendar mostRecent = null;
    final FileFilter ff = new WildcardFileFilter(Config.requireString(Config.PROJECT_NAME) + "*");
    final File[] dirs = Config.requireExistingDirectory(PROJECTS_DIR).listFiles(ff);

    for (final File d : dirs) {
        if (!d.isDirectory()
                || (d.getName().length() != (Config.requireString(Config.PROJECT_NAME).length() + 10))) {
            continue;
        }

        final String name = d.getName();
        final int len = name.length();
        final String year = name.substring(len - 9, len - 5);
        final String mon = name.substring(len - 5, len - 2);
        final String day = name.substring(len - 2);
        final Date date = new SimpleDateFormat("yyyyMMMdd").parse(year + mon + day);
        final GregorianCalendar projectDate = new GregorianCalendar();
        projectDate.setTime(date);

        // Value > 0 if projectDate has a more recent date than mostRecent
        if ((mostRecent == null) || (projectDate.compareTo(mostRecent) > 0)) {
            Log.addMsg("Found previous run = " + d.getAbsolutePath());
            restartDir = d;
            mostRecent = projectDate;
        }
    }

    if (restartDir == null) {
        throw new Exception(
                "Unalbe to locate restart directory in --> " + Config.requireExistingDirectory(PROJECTS_DIR));
    }

    if (isProjectComplete(restartDir)) {
        throw new Exception("RESTART FAILED!  Project ran successfully: " + restartDir.getAbsolutePath());
    }

    Log.addMsg(Constants.RETURN);
    Log.addMsg(Constants.RETURN);
    Log.addMsg(Constants.LOG_SPACER);
    Log.addMsg(Constants.LOG_SPACER);
    Log.addMsg(Constants.RETURN);
    Log.addMsg("RESTART PROJECT DIR --> " + restartDir.getAbsolutePath());
    Log.addMsg(Constants.RETURN);
    Log.addMsg(Constants.LOG_SPACER);
    Log.addMsg(Constants.LOG_SPACER);
    Log.addMsg(Constants.RETURN);

    return restartDir;
}

From source file:core.nipr.NiprClient.java

public void mergeReports(Map<String, LicenseInternal> aInDateInfo1, Map<String, LicenseInternal> aInDateInfo2) {

    for (LicenseInternal lLicense : aInDateInfo1.values()) {
        if (!aInDateInfo2.containsKey(lLicense.GetKey())) {
            aInDateInfo2.put(lLicense.GetKey(), lLicense);
        } else {//from   ww w .ja v a  2s  .com
            String lDate1Str = lLicense.niprUpdateDate;
            GregorianCalendar lDate1 = CalenderUtils.getCalenderTimeFromString(lDate1Str);
            String lDate2Str = aInDateInfo2.get(lLicense.GetKey()).niprUpdateDate;
            GregorianCalendar lDate2 = CalenderUtils.getCalenderTimeFromString(lDate2Str);

            if (lDate2.compareTo(lDate1) < 0) {
                aInDateInfo2.put(lLicense.GetKey(), lLicense);
            }
        }
    }
}

From source file:Main.java

public static int compareDate(String aDate, String bDate) {

    String[] strDate;/*w  w w.  ja v  a  2s. com*/
    GregorianCalendar aCal = new GregorianCalendar();
    GregorianCalendar bCal = new GregorianCalendar();
    if (aDate.indexOf("/") != -1) {
        strDate = aDate.split("/");
        aCal.set(Integer.parseInt(strDate[0].trim()), Integer.parseInt(strDate[1].trim()) - 1,
                Integer.parseInt(strDate[2].trim()));
    } else if (aDate.indexOf("-") != -1) {
        strDate = aDate.split("-");
        aCal.set(Integer.parseInt(strDate[0].trim()), Integer.parseInt(strDate[1].trim()) - 1,
                Integer.parseInt(strDate[2].trim()));
    } else if (aDate.length() == 8) {
        aCal.set(Integer.parseInt(aDate.substring(0, 4)), Integer.parseInt(aDate.substring(4, 6)) - 1,
                Integer.parseInt(aDate.substring(6, 8)));
    } else if (aDate.length() == 10) {
        aCal.set(Integer.parseInt(aDate.substring(0, 4)), Integer.parseInt(aDate.substring(5, 7)) - 1,
                Integer.parseInt(aDate.substring(8, 10)));
    }

    if (bDate.indexOf("/") != -1) {
        strDate = bDate.split("/");
        bCal.set(Integer.parseInt(strDate[0].trim()), Integer.parseInt(strDate[1].trim()) - 1,
                Integer.parseInt(strDate[2].trim()));
    } else if (bDate.indexOf("-") != -1) {
        strDate = bDate.split("-");
        bCal.set(Integer.parseInt(strDate[0].trim()), Integer.parseInt(strDate[1].trim()) - 1,
                Integer.parseInt(strDate[2].trim()));
    } else if (bDate.length() == 8) {
        bCal.set(Integer.parseInt(bDate.substring(0, 4)), Integer.parseInt(bDate.substring(4, 6)) - 1,
                Integer.parseInt(bDate.substring(6, 8)));
    } else if (bDate.length() == 10) {
        bCal.set(Integer.parseInt(bDate.substring(0, 4)), Integer.parseInt(bDate.substring(5, 7)) - 1,
                Integer.parseInt(bDate.substring(8, 10)));
    }

    return aCal.compareTo(bCal);
}

From source file:eu.europa.ec.markt.tlmanager.core.validation.Validation.java

/**
 * IssueDate must not be ulterior to the current time.
 *//* w w  w  .ja v a 2 s.  c o  m*/
private void checkRuleIssueDate() {
    GregorianCalendar listIssueTime = schemeInformation.getListIssueDateTime().toGregorianCalendar();
    GregorianCalendar gc = new GregorianCalendar();
    int result = listIssueTime.compareTo(gc);
    if (result == 1) {
        logger.warn(uiKeys.getString("Validation.rule.issueDate"), tsl);
    }
}

From source file:cx.fbn.nevernote.sql.REnSearch.java

public int dateCheck(String date, long noteDate) throws java.lang.NumberFormatException {
    int offset = 0;
    boolean found = false;
    GregorianCalendar calendar = new GregorianCalendar();

    if (date.contains("-")) {
        String modifier = date.substring(date.indexOf("-") + 1);
        offset = new Integer(modifier);
        offset = 0 - offset;/*from   www.ja  va2  s. c om*/
        date = date.substring(0, date.indexOf("-"));
    }

    if (date.contains("+")) {
        String modifier = date.substring(date.indexOf("+") + 1);
        offset = new Integer(modifier);
        date = date.substring(0, date.indexOf("+"));
    }

    if (date.equalsIgnoreCase("today")) {
        calendar.add(Calendar.DATE, offset);
        calendar.set(Calendar.HOUR, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 1);
        found = true;
    }

    if (date.equalsIgnoreCase("month")) {
        calendar.add(Calendar.MONTH, offset);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.HOUR, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 1);
        found = true;
    }

    if (date.equalsIgnoreCase("year")) {
        calendar.add(Calendar.YEAR, offset);
        calendar.set(Calendar.MONTH, Calendar.JANUARY);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.HOUR, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 1);
        found = true;
    }

    if (date.equalsIgnoreCase("week")) {
        calendar.add(Calendar.DATE, 0 - calendar.get(Calendar.DAY_OF_WEEK) + 1);
        calendar.add(Calendar.DATE, (offset * 7));
        calendar.set(Calendar.HOUR, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 1);

        found = true;
    }

    // If nothing was found, then we have a date number
    if (!found) {
        calendar = stringToGregorianCalendar(date);
    }

    String dateTimeFormat = new String("yyyyMMdd-HHmmss");
    SimpleDateFormat simple = new SimpleDateFormat(dateTimeFormat);
    StringBuilder creationDate = new StringBuilder(simple.format(noteDate));
    GregorianCalendar nCalendar = stringToGregorianCalendar(creationDate.toString().replace("-", "T"));
    if (calendar == null || nCalendar == null) // If we have something invalid, it automatically fails
        return 1;
    return calendar.compareTo(nCalendar);
}

From source file:op.tools.SYSCalendar.java

/**
 * Diese Routine vergleicht Uhrzeiten, die in zwei longs hinterlegt sind.
 * Das Besondere dabei ist, dass das Datum ausser acht gelassen wird.
 *
 * @return int < 0, wenn time1 < time2; int == 0, wenn time1 = time2; int > 0, wenn time1 > time2
 * @time1/*from  ww  w.  j  a va  2 s  .c  om*/
 * @time2
 */
public static int compareTime(long time1, long time2) {
    // normalisierung des timestamps
    GregorianCalendar gc1 = new GregorianCalendar();
    gc1.setTimeInMillis(time1);
    GregorianCalendar gc2 = new GregorianCalendar();
    gc2.setTimeInMillis(time2);
    gc2 = setDate2Time(gc1, gc2); // Hier werden die Daten gleichgesetzt.
    return gc1.compareTo(gc2);
}