List of usage examples for java.sql Timestamp compareTo
public int compareTo(java.util.Date o)
From source file:Main.java
public static void main(String[] args) { java.sql.Timestamp ts1 = java.sql.Timestamp.valueOf("2012-04-06 09:01:10"); java.sql.Timestamp ts2 = java.sql.Timestamp.valueOf("2013-04-06 09:01:10"); System.out.println(ts1.compareTo(ts2)); }
From source file:Main.java
public static void main(String[] args) { java.sql.Timestamp ts1 = java.sql.Timestamp.valueOf("2012-04-06 09:01:10"); java.sql.Timestamp ts2 = java.sql.Timestamp.valueOf("2013-04-06 09:01:10"); System.out.println(ts1.compareTo(new Date())); }
From source file:ips1ap101.lib.core.util.STP.java
public static boolean esObjetoEnRango(Object objeto, Object minimo, Object maximo) { boolean es = true; TipoDatoParEnumeration tipo;/*from w w w . j av a2s.c om*/ if (objeto == null) { return false; } else if (objeto instanceof String) { tipo = TipoDatoParEnumeration.ALFANUMERICO; } else if (objeto instanceof BigDecimal) { tipo = TipoDatoParEnumeration.NUMERICO; } else if (objeto instanceof Timestamp) { tipo = TipoDatoParEnumeration.FECHA_HORA; } else if (objeto instanceof Integer) { tipo = TipoDatoParEnumeration.ENTERO; } else if (objeto instanceof Long) { tipo = TipoDatoParEnumeration.ENTERO_GRANDE; } else if (objeto instanceof BigInteger) { tipo = TipoDatoParEnumeration.ENTERO_GRANDE; } else { return false; } switch (tipo) { case ALFANUMERICO: String val1 = (String) objeto; String min1 = (String) minimo; String max1 = (String) maximo; if (min1 != null && val1.compareTo(min1) < 0) { es = false; } if (max1 != null && val1.compareTo(max1) > 0) { es = false; } break; case NUMERICO: BigDecimal val2 = (BigDecimal) objeto; BigDecimal min2 = (BigDecimal) minimo; BigDecimal max2 = (BigDecimal) maximo; if (min2 != null && val2.compareTo(min2) < 0) { es = false; } if (max2 != null && val2.compareTo(max2) > 0) { es = false; } break; case FECHA_HORA: Timestamp val3 = (Timestamp) objeto; Timestamp min3 = (Timestamp) minimo; Timestamp max3 = (Timestamp) maximo; if (min3 != null && val3.compareTo(min3) < 0) { es = false; } if (max3 != null && val3.compareTo(max3) > 0) { es = false; } break; case ENTERO: Integer val4 = (Integer) objeto; Integer min4 = (Integer) minimo; Integer max4 = (Integer) maximo; if (min4 != null && val4.compareTo(min4) < 0) { es = false; } if (max4 != null && val4.compareTo(max4) > 0) { es = false; } break; case ENTERO_GRANDE: Long val5 = objeto instanceof BigInteger ? ((BigInteger) objeto).longValue() : (Long) objeto; Long min5 = (Long) minimo; Long max5 = (Long) maximo; if (min5 != null && val5.compareTo(min5) < 0) { es = false; } if (max5 != null && val5.compareTo(max5) > 0) { es = false; } break; } return es; }
From source file:com.egt.core.util.STP.java
public static boolean esObjetoEnRango(Object objeto, Object minimo, Object maximo) { boolean es = true; EnumTipoDatoPar tipo;//from ww w . j a v a 2 s .c om if (objeto == null) { return false; } else if (objeto instanceof String) { tipo = EnumTipoDatoPar.ALFANUMERICO; } else if (objeto instanceof BigDecimal) { tipo = EnumTipoDatoPar.NUMERICO; } else if (objeto instanceof Timestamp) { tipo = EnumTipoDatoPar.FECHA_HORA; } else if (objeto instanceof Integer) { tipo = EnumTipoDatoPar.ENTERO; } else if (objeto instanceof Long) { tipo = EnumTipoDatoPar.ENTERO_GRANDE; } else if (objeto instanceof BigInteger) { tipo = EnumTipoDatoPar.ENTERO_GRANDE; } else { return false; } switch (tipo) { case ALFANUMERICO: String val1 = (String) objeto; String min1 = (String) minimo; String max1 = (String) maximo; if (min1 != null && val1.compareTo(min1) < 0) { es = false; } if (max1 != null && val1.compareTo(max1) > 0) { es = false; } break; case NUMERICO: BigDecimal val2 = (BigDecimal) objeto; BigDecimal min2 = (BigDecimal) minimo; BigDecimal max2 = (BigDecimal) maximo; if (min2 != null && val2.compareTo(min2) < 0) { es = false; } if (max2 != null && val2.compareTo(max2) > 0) { es = false; } break; case FECHA_HORA: Timestamp val3 = (Timestamp) objeto; Timestamp min3 = (Timestamp) minimo; Timestamp max3 = (Timestamp) maximo; if (min3 != null && val3.compareTo(min3) < 0) { es = false; } if (max3 != null && val3.compareTo(max3) > 0) { es = false; } break; case ENTERO: Integer val4 = (Integer) objeto; Integer min4 = (Integer) minimo; Integer max4 = (Integer) maximo; if (min4 != null && val4.compareTo(min4) < 0) { es = false; } if (max4 != null && val4.compareTo(max4) > 0) { es = false; } break; case ENTERO_GRANDE: Long val5 = objeto instanceof BigInteger ? ((BigInteger) objeto).longValue() : (Long) objeto; Long min5 = (Long) minimo; Long max5 = (Long) maximo; if (min5 != null && val5.compareTo(min5) < 0) { es = false; } if (max5 != null && val5.compareTo(max5) > 0) { es = false; } break; } return es; }
From source file:ips1ap101.lib.base.util.StrUtils.java
public static boolean esObjetoEnRango(Object objeto, Object minimo, Object maximo) { boolean es = true; // EnumTipoDatoParametro tipo; if (objeto == null) { return false; } else if (objeto instanceof String) { // tipo = EnumTipoDatoParametro.ALFANUMERICO; String val1 = (String) objeto; String min1 = (String) minimo; String max1 = (String) maximo; if (min1 != null && val1.compareTo(min1) < 0) { es = false;/*from w w w . j av a 2 s.c o m*/ } if (max1 != null && val1.compareTo(max1) > 0) { es = false; } } else if (objeto instanceof Integer) { // tipo = EnumTipoDatoParametro.ENTERO; Integer val4 = (Integer) objeto; Integer min4 = (Integer) minimo; Integer max4 = (Integer) maximo; if (min4 != null && val4.compareTo(min4) < 0) { es = false; } if (max4 != null && val4.compareTo(max4) > 0) { es = false; } } else if (objeto instanceof Long || objeto instanceof BigInteger) { // tipo = EnumTipoDatoParametro.ENTERO_GRANDE; Long val5 = objeto instanceof BigInteger ? ((BigInteger) objeto).longValue() : (Long) objeto; Long min5 = (Long) minimo; Long max5 = (Long) maximo; if (min5 != null && val5.compareTo(min5) < 0) { es = false; } if (max5 != null && val5.compareTo(max5) > 0) { es = false; } } else if (objeto instanceof BigDecimal) { // tipo = EnumTipoDatoParametro.NUMERICO; BigDecimal val2 = (BigDecimal) objeto; BigDecimal min2 = (BigDecimal) minimo; BigDecimal max2 = (BigDecimal) maximo; if (min2 != null && val2.compareTo(min2) < 0) { es = false; } if (max2 != null && val2.compareTo(max2) > 0) { es = false; } } else if (objeto instanceof Timestamp) { // tipo = EnumTipoDatoParametro.FECHA_HORA; Timestamp val3 = (Timestamp) objeto; Timestamp min3 = (Timestamp) minimo; Timestamp max3 = (Timestamp) maximo; if (min3 != null && val3.compareTo(min3) < 0) { es = false; } if (max3 != null && val3.compareTo(max3) > 0) { es = false; } } else { return false; } return es; }
From source file:fr.paris.lutece.plugins.document.business.Document.java
/** * Control that an document is valid, i.e. that its period of validity * defined/*from w w w . j av a2 s. c om*/ * by its dateValidityBegin and its dateValidityEnd is valid : * an document is valid if the current date > = dateValidityBegin and if * current date < = dateValidityEnd * If the two dates are null, the test of validity will return true * if one of the dates is null, the result of the test will be that carried * out * on the non null date * @return true if the document is valid, false otherwise */ public boolean isValid() { java.sql.Timestamp dateValidityBegin = getDateValidityBegin(); java.sql.Timestamp dateValidityEnd = getDateValidityEnd(); GregorianCalendar gc = new GregorianCalendar(); java.sql.Date dateToday = new java.sql.Date(gc.getTime().getTime()); if ((dateValidityBegin == null) && (dateValidityEnd == null)) { return true; } else if (dateValidityBegin == null) { // Return true if dateValidityEnd >= DateToday, false otherwise : return (dateValidityEnd.compareTo(dateToday) >= 0); } else if (dateValidityEnd == null) { // Return true if dateValidityBegin <= DateToday, false otherwise : return (dateValidityBegin.compareTo(dateToday) <= 0); } else { // Return true if dateValidityBegin <= dateToday <= dateValidityEnd, false // otherwise : return ((dateValidityBegin.compareTo(dateToday) <= 0) && (dateValidityEnd.compareTo(dateToday) >= 0)); } }
From source file:org.eevolution.form.VCRP.java
public boolean checkResourceAvailability(Timestamp dateTime, MResource r) { int[] ids = PO.getAllIDs("S_ResourceUnAvailable", "S_Resource_ID = " + r.get_ID() + " AND AD_Client_ID = " + r.getAD_Client_ID(), null); Timestamp dateFrom = null; Timestamp dateTo = null;/* w w w. jav a 2 s . c o m*/ Timestamp dateActual = null; MResourceUnAvailable rua = null; for (int i = 0; i < ids.length; i++) { rua = new MResourceUnAvailable(Env.getCtx(), ids[i], null); dateFrom = DateTimeUtil.getDayBorder(rua.getDateFrom(), null, false); dateTo = DateTimeUtil.getDayBorder(rua.getDateTo(), null, true); dateActual = DateTimeUtil.getDayBorder(dateTime, null, false); if (dateFrom.compareTo(dateActual) <= 0 && dateTo.compareTo(dateActual) >= 0) { return false; } } return true; }
From source file:edu.ku.brc.specify.datamodel.CollectionObject.java
public int compareTo(CollectionObject obj) { if (obj == null) return 1; String myCatNum = catalogNumber == null ? "" : catalogNumber; String objCatNum = obj.catalogNumber == null ? "" : obj.catalogNumber; if (!"".equals(myCatNum) || !"".equals(objCatNum)) { return myCatNum.compareTo(objCatNum); } else {//w w w. j ava 2 s . c o m Timestamp myStamp = timestampCreated; Timestamp objStamp = obj.timestampCreated; if (myStamp != null && objStamp != null) { return myStamp.compareTo(objStamp); } else if (myStamp != null) { return 1; } else if (objStamp != null) { return -1; } else { return 0; } } }
From source file:com.google.gerrit.acceptance.server.notedb.ChangeRebuilderIT.java
private ChangeMessage insertMessage(Change.Id id, PatchSet.Id psId, Account.Id author, Timestamp ts, String message) throws Exception { ChangeMessage msg = new ChangeMessage(new ChangeMessage.Key(id, ChangeUtil.messageUuid()), author, ts, psId);/*from www. j a va 2 s. c om*/ msg.setMessage(message); db.changeMessages().insert(Collections.singleton(msg)); Change c = db.changes().get(id); if (ts.compareTo(c.getLastUpdatedOn()) > 0) { c.setLastUpdatedOn(ts); db.changes().update(Collections.singleton(c)); } return msg; }
From source file:org.kuali.kfs.module.purap.document.service.impl.PaymentRequestServiceImpl.java
/** * @see org.kuali.kfs.module.purap.document.service.PaymentRequestService#isInvoiceDateAfterToday(java.sql.Date) *//* www .ja v a 2 s .c om*/ @Override @NonTransactional public boolean isInvoiceDateAfterToday(Date invoiceDate) { // Check invoice date to make sure it is today or before Calendar now = Calendar.getInstance(); now.set(Calendar.HOUR, 11); now.set(Calendar.MINUTE, 59); now.set(Calendar.SECOND, 59); now.set(Calendar.MILLISECOND, 59); Timestamp nowTime = new Timestamp(now.getTimeInMillis()); Calendar invoiceDateC = Calendar.getInstance(); invoiceDateC.setTime(invoiceDate); // set time to midnight invoiceDateC.set(Calendar.HOUR, 0); invoiceDateC.set(Calendar.MINUTE, 0); invoiceDateC.set(Calendar.SECOND, 0); invoiceDateC.set(Calendar.MILLISECOND, 0); Timestamp invoiceDateTime = new Timestamp(invoiceDateC.getTimeInMillis()); return ((invoiceDateTime.compareTo(nowTime)) > 0); }