Example usage for java.sql Timestamp before

List of usage examples for java.sql Timestamp before

Introduction

In this page you can find the example usage for java.sql Timestamp before.

Prototype

public boolean before(Timestamp ts) 

Source Link

Document

Indicates whether this Timestamp object is earlier than the given Timestamp object.

Usage

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.before(ts2));

}

From source file:de.fraunhofer.iosb.ilt.sta.persistence.postgres.PropertyHelper.java

private static TimeInterval intervalFromTimes(Timestamp timeStart, Timestamp timeEnd) {
    if (timeStart == null) {
        timeStart = Timestamp.valueOf(LocalDateTime.MAX);
    }/*from  w w w .j a  v a 2s . c  o m*/
    if (timeEnd == null) {
        timeEnd = Timestamp.valueOf(LocalDateTime.MIN);
    }
    if (timeEnd.before(timeStart)) {
        return null;
    } else {
        return TimeInterval.create(timeStart.getTime(), timeEnd.getTime());
    }
}

From source file:org.kuali.kfs.module.ar.document.service.impl.CustomerAddressServiceImpl.java

/**
 * This method returns true if customer address is active
 *
 * @param customerNumber//from www.  jav  a2 s . com
 * @param customerAddressIdentifier
 * @return
 */
@Override
public boolean customerAddressActive(String customerNumber, Integer customerAddressIdentifier) {

    CustomerAddress customerAddress = getByPrimaryKey(customerNumber, customerAddressIdentifier);

    if (ObjectUtils.isNotNull(customerAddress)) {
        if (ObjectUtils.isNotNull(customerAddress.getCustomerAddressEndDate())) {
            Timestamp currentDateTimestamp = new Timestamp(dateTimeService.getCurrentDate().getTime());
            Timestamp addressEndDateTimestamp = new Timestamp(
                    customerAddress.getCustomerAddressEndDate().getTime());
            if (addressEndDateTimestamp.before(currentDateTimestamp)) {
                return false;
            }
        }
    }
    return true;
}

From source file:hoot.services.osm.OsmTestUtils.java

public static void verifyNode(final Document responseData, final long index, final String expectedId,
        final long changesetId, final double lat, final double lon, final boolean multiLayerUniqueElementIds) {
    try {//from  w w  w  . j a  v a  2 s.c  om
        XPath xpath = XmlDocumentBuilder.createXPath();
        if (!multiLayerUniqueElementIds) {
            Assert.assertEquals(Long.parseLong(expectedId),
                    Long.parseLong(xpath.evaluate("//osm/node[" + index + "]/@id", responseData)));
        } else {
            Assert.assertEquals(expectedId, xpath.evaluate("//osm/node[" + index + "]/@id", responseData));
        }
        Assert.assertEquals(true,
                Boolean.parseBoolean(xpath.evaluate("//osm/node[" + index + "]/@visible", responseData)));
        Assert.assertEquals(1,
                Long.parseLong(xpath.evaluate("//osm/node[" + index + "]/@version", responseData)));
        Assert.assertEquals(changesetId,
                Long.parseLong(xpath.evaluate("//osm/node[" + index + "]/@changeset", responseData)));

        String timeStampStr = xpath.evaluate("//osm/node[" + index + "]/@timestamp", responseData);
        //remove the millseconds portion of the string, since it can be of variable length and cause
        //seemingly random problems when parsed
        if (timeStampStr.contains(".")) {
            timeStampStr = timeStampStr.split("\\.")[0];
        }

        Timestamp nodeTimestamp = new Timestamp(timeFormatter.parseDateTime(timeStampStr).getMillis());
        final Timestamp now = new Timestamp(Calendar.getInstance().getTimeInMillis());
        Assert.assertTrue(nodeTimestamp.before(now));
        Assert.assertEquals("user-with-id-" + userId,
                xpath.evaluate("//osm/node[" + index + "]/@user", responseData));
        Assert.assertEquals(userId,
                Long.parseLong(xpath.evaluate("//osm/node[" + index + "]/@uid", responseData)));
        Assert.assertEquals(DbUtils.toDbCoordPrecision(lat),
                Double.parseDouble(xpath.evaluate("//osm/node[" + index + "]/@lat", responseData)), 0.0);
        Assert.assertEquals(DbUtils.toDbCoordPrecision(lon),
                Double.parseDouble(xpath.evaluate("//osm/node[" + index + "]/@lon", responseData)), 0.0);
    } catch (Exception e) {
        Assert.fail("Error parsing node from response document: " + e.getMessage());
    }
}

From source file:hoot.services.osm.OsmTestUtils.java

public static void verifyWay(final Document responseData, final long index, final String expectedId,
        final long changesetId, final Set<Long> expectedWayNodeIds, final boolean multiLayerUniqueElementIds) {
    try {/*from   w w  w.  j  a  v a 2 s .com*/
        XPath xpath = XmlDocumentBuilder.createXPath();

        if (!multiLayerUniqueElementIds) {
            Assert.assertEquals(Long.parseLong(expectedId),
                    Long.parseLong(xpath.evaluate("//osm/way[" + index + "]/@id", responseData)));
        } else {
            Assert.assertEquals(expectedId, xpath.evaluate("//osm/way[" + index + "]/@id", responseData));
        }
        Assert.assertEquals(true,
                Boolean.parseBoolean(xpath.evaluate("//osm/way[" + index + "]/@visible", responseData)));
        Assert.assertEquals(1,
                Long.parseLong(xpath.evaluate("//osm/way[" + index + "]/@version", responseData)));
        Assert.assertEquals(changesetId,
                Long.parseLong(xpath.evaluate("//osm/way[" + index + "]/@changeset", responseData)));

        String timeStampStr = xpath.evaluate("//osm/way[" + index + "]/@timestamp", responseData);
        //remove the millseconds portion of the string, since it can be of variable length and cause
        //seemingly random problems when parsed
        if (timeStampStr.contains(".")) {
            timeStampStr = timeStampStr.split("\\.")[0];
        }

        Timestamp wayTimestamp = new Timestamp(timeFormatter.parseDateTime(timeStampStr).getMillis());
        final Timestamp now = new Timestamp(Calendar.getInstance().getTimeInMillis());
        Assert.assertTrue(wayTimestamp.before(now));
        Assert.assertEquals("user-with-id-" + userId,
                xpath.evaluate("//osm/way[" + index + "]/@user", responseData));
        Assert.assertEquals(userId,
                Long.parseLong(xpath.evaluate("//osm/way[" + index + "]/@uid", responseData)));

        if (expectedWayNodeIds != null) {
            final Long[] expectedWayNodeIdsArr = expectedWayNodeIds.toArray(new Long[] {});
            Assert.assertEquals(expectedWayNodeIdsArr.length,
                    XPathAPI.selectNodeList(responseData, "//osm/way[" + index + "]/nd").getLength());
            for (int i = 0; i < expectedWayNodeIdsArr.length; i++) {
                Assert.assertEquals((long) expectedWayNodeIdsArr[i], Long.parseLong(
                        xpath.evaluate("//osm/way[" + index + "]/nd[" + (i + 1) + "]/@ref", responseData)));
            }
        }
    } catch (Exception e) {
        Assert.fail("Error parsing way from response document: " + e.getMessage());
    }
}

From source file:hoot.services.osm.OsmTestUtils.java

public static void verifyRelation(final Document responseData, final long index, final String expectedId,
        final long changesetId, final List<RelationMember> expectedMembers,
        final boolean multiLayerUniqueElementIds) {
    try {//from w  w w. j a v a 2  s.  c  o m
        XPath xpath = XmlDocumentBuilder.createXPath();

        if (!multiLayerUniqueElementIds) {
            Assert.assertEquals(Long.parseLong(expectedId),
                    Long.parseLong(xpath.evaluate("//osm/relation[" + index + "]/@id", responseData)));
        } else {
            Assert.assertEquals(expectedId, xpath.evaluate("//osm/relation[" + index + "]/@id", responseData));
        }
        Assert.assertEquals(true,
                Boolean.parseBoolean(xpath.evaluate("//osm/relation[" + index + "]/@visible", responseData)));
        Assert.assertEquals(1,
                Long.parseLong(xpath.evaluate("//osm/relation[" + index + "]/@version", responseData)));
        Assert.assertEquals(changesetId,
                Long.parseLong(xpath.evaluate("//osm/relation[" + index + "]/@changeset", responseData)));

        String timeStampStr = xpath.evaluate("//osm/relation[" + index + "]/@timestamp", responseData);
        //remove the millseconds portion of the string, since it can be of variable length and cause
        //seemingly random problems when parsed
        if (timeStampStr.contains(".")) {
            timeStampStr = timeStampStr.split("\\.")[0];
        }

        Timestamp relationTimestamp = new Timestamp(timeFormatter.parseDateTime(timeStampStr).getMillis());
        final Timestamp now = new Timestamp(Calendar.getInstance().getTimeInMillis());
        Assert.assertTrue(relationTimestamp.before(now));
        Assert.assertEquals("user-with-id-" + userId,
                xpath.evaluate("//osm/relation[" + index + "]/@user", responseData));
        Assert.assertEquals(userId,
                Long.parseLong(xpath.evaluate("//osm/relation[" + index + "]/@uid", responseData)));

        if (expectedMembers != null) {
            Assert.assertEquals(expectedMembers.size(),
                    XPathAPI.selectNodeList(responseData, "//osm/relation[" + index + "]/member").getLength());
            int memberCtr = 1;
            for (RelationMember member : expectedMembers) {
                Assert.assertEquals(member.getId(), Long.parseLong(xpath.evaluate(
                        "//osm/relation[" + index + "]/member[" + memberCtr + "]/@ref", responseData)));
                Assert.assertEquals(member.getRole(), xpath.evaluate(
                        "//osm/relation[" + index + "]/member[" + memberCtr + "]/@role", responseData));
                Assert.assertEquals(member.getType().toString().toLowerCase(), xpath.evaluate(
                        "//osm/relation[" + index + "]/member[" + memberCtr + "]/@type", responseData));

                memberCtr++;
            }
        }
    } catch (Exception e) {
        Assert.fail("Error parsing relation from response document: " + e.getMessage());
    }
}

From source file:product.ValidateToken.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    JSONObject arrayObj = new JSONObject();
    String access_token = request.getParameter("access_token");
    String query = "SELECT * FROM tokendata WHERE token='" + access_token + "'";

    try {//from  ww  w .j a v a  2 s. co m
        Connection currentCon = ConnectionManager.getConnection();
        Statement stmt = currentCon.createStatement();
        ResultSet rs = stmt.executeQuery(query);
        boolean valid = rs.next();
        System.out.println("ADA TOKEN TAU GAK = " + valid);

        if (valid) {

            Timestamp create_time = getTimeStamp(access_token);
            Calendar cal = Calendar.getInstance();
            cal.setTimeInMillis(create_time.getTime());
            cal.add(Calendar.MINUTE, 30);
            Timestamp expired_time = new Timestamp(cal.getTimeInMillis());
            Timestamp current_time = new Timestamp(System.currentTimeMillis());

            if (expired_time.before(current_time)) {
                arrayObj.put("status", "expired");
            } else {
                arrayObj = getJsonObj(access_token);
                setCreateTime(getUserID(access_token), access_token, current_time);
            }
        } else {
            arrayObj.put("status", "non-valid");
        }
    } catch (SQLException se) {
        System.out.println(se);
    }
    response.setContentType("application/json:charset=UTF-8");
    response.getWriter().write(arrayObj.toString());
}

From source file:org.kuali.kfs.module.ar.document.service.impl.InvoiceRecurrenceDocumentServiceImpl.java

/**
 * @see org.kuali.kfs.module.ar.document.service.InvoiceRecurrenceService#isValidRecurrenceBeginDate(Date)
 *//*  w  w  w.  ja v a 2  s . c  om*/
@Override
public boolean isValidRecurrenceBeginDate(Date beginDate) {
    boolean isSuccess = true;
    if (ObjectUtils.isNull(beginDate)) {
        return isSuccess;
    }
    Timestamp currentDate = new Timestamp(dateTimeService.getCurrentDate().getTime());
    Timestamp beginDateTimestamp = new Timestamp(beginDate.getTime());
    if (beginDateTimestamp.before(currentDate) || beginDateTimestamp.equals(currentDate)) {
        return false;
    }
    return isSuccess;
}

From source file:org.kuali.rice.kim.document.rule.IdentityManagementGroupDocumentRule.java

protected boolean validateActiveDate(String errorPath, Timestamp activeFromDate, Timestamp activeToDate) {
    // TODO : do not have detail bus rule yet, so just check this for now.
    boolean valid = true;
    if (activeFromDate != null && activeToDate != null && activeToDate.before(activeFromDate)) {
        MessageMap errorMap = GlobalVariables.getMessageMap();
        errorMap.putError(errorPath, RiceKeyConstants.ERROR_ACTIVE_TO_DATE_BEFORE_FROM_DATE);
        valid = false;// ww  w .j  a  va 2  s.c om

    }
    return valid;
}

From source file:org.kuali.kfs.module.ar.document.validation.impl.InvoiceRecurrenceRule.java

/**
 * Validate Begin Date./*from w w w.ja  v  a 2  s . c o m*/
 */
protected boolean validateDocumentRecurrenceBeginDate(InvoiceRecurrence newInvoiceRecurrence) {
    boolean success = true;
    if (ObjectUtils.isNull(newInvoiceRecurrence.getDocumentRecurrenceBeginDate())) {
        return success;
    }
    Timestamp currentDate = new Timestamp(getDateTimeService().getCurrentDate().getTime());
    Timestamp beginDateTimestamp = new Timestamp(
            newInvoiceRecurrence.getDocumentRecurrenceBeginDate().getTime());
    if (beginDateTimestamp.before(currentDate) || beginDateTimestamp.equals(currentDate)) {
        putFieldError(ArPropertyConstants.InvoiceRecurrenceFields.INVOICE_RECURRENCE_BEGIN_DATE,
                ArKeyConstants.ERROR_INVOICE_RECURRENCE_BEGIN_DATE_EARLIER_THAN_TODAY);
        return false;
    }
    return success;
}