Example usage for java.util Date compareTo

List of usage examples for java.util Date compareTo

Introduction

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

Prototype

public int compareTo(Date anotherDate) 

Source Link

Document

Compares two Dates for ordering.

Usage

From source file:org.petclinic.web.VisitsAtomView.java

@Override
protected void buildFeedMetadata(Map<String, Object> model, Feed feed, HttpServletRequest request) {
    feed.setId("tag:springsource.com");
    feed.setTitle("Pet Clinic Visits");
    @SuppressWarnings("unchecked")
    List<Visit> visits = (List<Visit>) model.get("visits");
    for (Visit visit : visits) {
        Date date = visit.getDate();
        if (feed.getUpdated() == null || date.compareTo(feed.getUpdated()) > 0) {
            feed.setUpdated(date);//from   w w  w . ja  va 2 s  .  co m
        }
    }
}

From source file:com.bolsadeideas.ejemplos.cuenta.views.CuentaAtomView.java

@Override
protected void buildFeedMetadata(Map<String, Object> model, Feed feed, HttpServletRequest request) {
    feed.setId("tag:bolsadeideas.com");
    feed.setTitle("Lista de cuentas");
    @SuppressWarnings("unchecked")
    List<Cuenta> cuentas = (List<Cuenta>) model.get("cuentas");
    for (Cuenta cuenta : cuentas) {
        Date fecha = cuenta.getFechaRenovacion();
        if (feed.getUpdated() == null || fecha.compareTo(feed.getUpdated()) > 0) {
            feed.setUpdated(fecha);/*from w ww.j  a v a  2  s . co m*/
        }
    }
}

From source file:org.kuali.kfs.gl.web.util.OriginEntryFileComparator.java

public int compare(File o1, File o2) {
    String fileName1 = o1.getName();
    String fileName2 = o2.getName();

    // remove date from name
    fileName1 = StringUtils.substringBefore(fileName1, ".");
    fileName2 = StringUtils.substringBefore(fileName2, ".");

    int c = fileName1.compareTo(fileName2);
    if (c != 0) {
        return c;
    }/*from  w  w  w  .j  a v a 2  s .c om*/

    Date fileDate1 = new Date(o1.lastModified());
    Date fileDate2 = new Date(o2.lastModified());

    return fileDate1.compareTo(fileDate2);
}

From source file:com.bolsadeideas.ejemplos.cuenta.views.CuentaRssView.java

@Override
protected void buildFeedMetadata(Map<String, Object> model, Channel feed, HttpServletRequest request) {
    feed.setTitle("Lista de cuentas");
    feed.setDescription("Ejemplo RSS feed");
    feed.setLink("www.bolsadeideas.com");

    @SuppressWarnings("unchecked")
    List<Cuenta> cuentas = (List<Cuenta>) model.get("cuentas");

    for (Cuenta cuenta : cuentas) {
        Date fecha = cuenta.getFechaRenovacion();
        if ((feed.getLastBuildDate() == null) || (fecha.compareTo(feed.getLastBuildDate()) > 0)) {
            feed.setLastBuildDate(fecha);
        }//from   ww  w .j  ava  2 s.  c om
    }
}

From source file:com.huateng.ebank.framework.util.DateUtil.java

/**
 * ??//w  w w  .  ja v  a  2s .c o  m
 * @param startDate
 * @param endDate
 * @return YYMMDD??
 */
public static String getTermBetween(Date startDate, Date endDate) {
    Calendar calendarStartDate = Calendar.getInstance();
    Calendar calendarEndDate = Calendar.getInstance();

    // 
    calendarStartDate.setTime(startDate);
    calendarEndDate.setTime(endDate);
    if (startDate.after(endDate)) {
        Calendar swap = calendarStartDate;
        calendarStartDate = calendarEndDate;
        calendarEndDate = swap;
    }

    int months = calendarEndDate.get(Calendar.MONTH) - calendarStartDate.get(Calendar.MONTH)
            + (calendarEndDate.get(Calendar.YEAR) - calendarStartDate.get(Calendar.YEAR)) * 12;
    int days = 0;
    Date tempEndDate = getEndDateByMonths(startDate, months);

    if (tempEndDate.compareTo(endDate) < 0) {
        days = getDaysBetween(tempEndDate, endDate);
    } else if (tempEndDate.compareTo(endDate) > 0) {
        months -= 1;
        tempEndDate = getEndDateByMonths(startDate, months);
        days = getDaysBetween(tempEndDate, endDate);
    }

    int years = months / 12;
    months = months % 12;

    return DataFormat.termToString(years, months, days);
}

From source file:org.openmrs.module.drughistory.api.impl.DrugEventServiceImpl.java

@Override
public List<DrugEvent> getAllDrugEvents(Date sinceWhen) {
    if (sinceWhen != null && sinceWhen.compareTo(new Date()) > 0) {
        throw new IllegalArgumentException("Date: " + sinceWhen + " should be earlier than or equal to today");
    }/* w w w.  j a  v  a 2 s  .  c o m*/

    Properties params = new Properties();
    if (sinceWhen != null) {
        params.put("since", sinceWhen);
    }

    return dao.getDrugEvents(params);
}

From source file:com.huateng.ebank.framework.util.DateUtil.java

/**
        //from   www. j  a va 2s  .c  om
* 30?
        
* @param
        
* @return 
        
*/
public static int getDaysBetween30(Date startDate, Date endDate) {

    Calendar calendarStartDate = Calendar.getInstance();

    Calendar calendarEndDate = Calendar.getInstance();

    // 

    calendarStartDate.setTime(startDate);

    calendarEndDate.setTime(endDate);

    if (startDate.after(endDate)) {

        Calendar swap = calendarStartDate;

        calendarStartDate = calendarEndDate;

        calendarEndDate = swap;

    }

    int months =

            calendarEndDate.get(Calendar.MONTH)

                    - calendarStartDate.get(Calendar.MONTH)

                    + (calendarEndDate.get(Calendar.YEAR)

                            - calendarStartDate.get(Calendar.YEAR))

                            * 12;

    Date newEndDate = getEndDateByMonths(startDate, months);

    if (newEndDate.compareTo(endDate) <= 0

            || isSameDate(newEndDate, endDate) == true)

        months += 1;

    int days = (months - 1) * 30;

    Date newStartDate = getEndDateByMonths(startDate, months - 1);

    days += getDaysBetween(newStartDate, endDate);

    return days;

}

From source file:org.openmrs.module.drughistory.api.impl.DrugEventServiceImpl.java

@Override
public void generateAllDrugEvents(Person person, Date sinceWhen) {
    if (sinceWhen != null) {
        if (sinceWhen.compareTo(new Date()) > 0) {
            throw new IllegalArgumentException(
                    "Date: " + sinceWhen + " should be greater than the date of today");
        } else {//from www.ja v a 2  s  .  co  m

        }
    } else {
        //All drug events.
    }
}

From source file:com.odoo.addons.phonecall.models.CRMPhoneCalls.java

public void setReminder(int row_id) {
    ODataRow row = browse(row_id);/* w w w .j a va2  s .c om*/
    Date start_date = ODateUtils.createDateObject(row.getString("date"), ODateUtils.DEFAULT_FORMAT, false);
    Date now = new Date();
    if (now.compareTo(start_date) < 0) {
        Bundle extra = row.getPrimaryBundleData();
        extra.putString(ReminderUtils.KEY_REMINDER_TYPE, "phonecall");
        if (ReminderUtils.get(mContext).resetReminder(start_date, extra)) {
            OValues values = new OValues();
            values.put("_is_dirty", "false");
            values.put("has_reminder", "true");
            update(row_id, values);
        }
    }
}

From source file:messenger.YahooFinanceAPI.java

public Double getKSPercent() {
    String contents = httpget(url + "%5EKS11" + format);
    //System.out.println(contents);
    String[] content = contents.split(",");

    Date Kdate = transDate(content[5].replaceAll("\"", ""));
    Date today = getToday();
    int i = today.compareTo(Kdate);
    if (i == 0) {
        double price = Double.parseDouble(content[1]);
        double vol = Double.parseDouble(content[8].replace("\"", "").replace("+", ""));
        return vol / price;
    } else {/*from w  ww.jav  a 2s  .  co m*/
        return null;
    }

}