Example usage for java.sql Time equals

List of usage examples for java.sql Time equals

Introduction

In this page you can find the example usage for java.sql Time equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Compares two dates for equality.

Usage

From source file:com.alibaba.wasp.jdbc.TestJdbcResultSet.java

@Test
public void testDatetime() throws SQLException {
    trace("test DATETIME");
    ResultSet rs;//from  w  w w.j  a  v a2 s.co  m
    Object o;

    // rs = stat.executeQuery("call date '99999-12-23'");
    // rs.next();
    // assertEquals("99999-12-23", rs.getString(1));
    // rs = stat.executeQuery("call timestamp '99999-12-23 01:02:03.000'");
    // rs.next();
    // assertEquals("99999-12-23 01:02:03.0", rs.getString(1));
    // rs = stat.executeQuery("call date '-99999-12-23'");
    // rs.next();
    // assertEquals("-99999-12-23", rs.getString(1));
    // rs = stat.executeQuery("call timestamp '-99999-12-23 01:02:03.000'");
    // rs.next();
    // assertEquals("-99999-12-23 01:02:03.0", rs.getString(1));

    stat = conn.createStatement();
    // stat.execute("CREATE TABLE test(ID INT PRIMARY KEY,VALUE DATETIME)");
    stat.execute(
            "INSERT INTO test (column1,column6,column2,column3) VALUES (1,'2011-11-11 0:0:0', 13, 'testDatetime')");
    stat.execute(
            "INSERT INTO test (column1,column6,column2,column3) VALUES (2,'2002-02-02 02:02:02', 13, 'testDatetime')");
    stat.execute(
            "INSERT INTO test (column1,column6,column2,column3) VALUES (3,'1800-01-01 0:0:0', 13, 'testDatetime')");
    stat.execute(
            "INSERT INTO test (column1,column6,column2,column3) VALUES (4,'9999-12-31 23:59:59', 13, 'testDatetime')");
    stat.execute(
            "INSERT INTO test (column1,column6,column2,column3) VALUES (5,'9999-12-31 23:59:59', 13, 'testDatetime')");
    // stat.execute("INSERT INTO test (column1,column6,column2,column3) VALUES(5,NULL)");
    rs = stat.executeQuery("SELECT column1,column6 FROM test where column3='testDatetime' ORDER BY column1");
    // assertResultSetMeta(rs, 2, new String[] { "ID", "VALUE" }, new int[] {
    // Types.INTEGER, Types.TIMESTAMP }, new int[] { 10, 23 }, new int[] { 0,
    // 10 });
    // rs = stat.executeQuery("SELECT * FROM test ORDER BY ID");
    // assertResultSetMeta(rs, 2, new String[] { "ID", "VALUE" }, new int[] {
    // Types.INTEGER, Types.TIMESTAMP }, new int[] { 10, 23 }, new int[] { 0,
    // 10 });
    rs.next();
    java.sql.Date date;
    java.sql.Time time;
    Timestamp ts;
    date = rs.getDate(2);
    assertTrue(!rs.wasNull());
    time = rs.getTime(2);
    assertTrue(!rs.wasNull());
    ts = rs.getTimestamp(2);
    assertTrue(!rs.wasNull());
    trace("Date: " + date.toString() + " Time:" + time.toString() + " Timestamp:" + ts.toString());
    trace("Date ms: " + date.getTime() + " Time ms:" + time.getTime() + " Timestamp ms:" + ts.getTime());
    trace("1970 ms: " + Timestamp.valueOf("1970-01-01 00:00:00.0").getTime());
    assertEquals(Timestamp.valueOf("2011-11-11 00:00:00.0").getTime(), date.getTime());
    assertEquals(Timestamp.valueOf("1970-01-01 00:00:00.0").getTime(), time.getTime());
    assertEquals(Timestamp.valueOf("2011-11-11 00:00:00.0").getTime(), ts.getTime());
    assertTrue(date.equals(java.sql.Date.valueOf("2011-11-11")));
    assertTrue(time.equals(java.sql.Time.valueOf("00:00:00")));
    assertTrue(ts.equals(Timestamp.valueOf("2011-11-11 00:00:00.0")));
    assertFalse(rs.wasNull());
    o = rs.getObject(2);
    trace(o.getClass().getName());
    assertTrue(o instanceof Timestamp);
    assertTrue(((Timestamp) o).equals(Timestamp.valueOf("2011-11-11 00:00:00")));
    assertFalse(rs.wasNull());
    rs.next();
    date = rs.getDate("COLUMN6");
    assertTrue(!rs.wasNull());
    time = rs.getTime("COLUMN6");
    assertTrue(!rs.wasNull());
    ts = rs.getTimestamp("COLUMN6");
    assertTrue(!rs.wasNull());
    trace("Date: " + date.toString() + " Time:" + time.toString() + " Timestamp:" + ts.toString());
    assertEquals("2002-02-02", date.toString());
    assertEquals("02:02:02", time.toString());
    assertEquals("2002-02-02 02:02:02.0", ts.toString());
    rs.next();
    assertEquals("1800-01-01", rs.getDate("column6").toString());
    assertEquals("00:00:00", rs.getTime("column6").toString());
    assertEquals("1800-01-01 00:00:00.0", rs.getTimestamp("column6").toString());
    rs.next();
    assertEquals("9999-12-31", rs.getDate("Column6").toString());
    assertEquals("23:59:59", rs.getTime("Column6").toString());
    assertEquals("9999-12-31 23:59:59.0", rs.getTimestamp("Column6").toString());
    // assertTrue(!rs.next());
}

From source file:org.sakaiproject.tool.section.decorator.SectionDecorator.java

/**
 * Compares SectionDecorators by the section's first meeting times.
 *
 * @param sortAscending/*w  w  w . j  a v  a 2 s.  c  om*/
 * @return
 */
public static final Comparator<SectionDecorator> getTimeComparator(final boolean sortAscending) {
    return new Comparator<SectionDecorator>() {
        public int compare(SectionDecorator section1, SectionDecorator section2) {

            // First compare the category name, then compare the time
            int categoryNameComparison = section1.getCategory().compareTo(section2.getCategory());
            if (categoryNameComparison == 0) {
                // These are in the same category, so compare by the first meeting time
                List meetings1 = section1.getDecoratedMeetings();
                List meetings2 = section2.getDecoratedMeetings();

                MeetingDecorator meeting1 = (MeetingDecorator) meetings1.get(0);
                MeetingDecorator meeting2 = (MeetingDecorator) meetings2.get(0);

                Time startTime1 = meeting1.getStartTime();
                Time startTime2 = meeting2.getStartTime();

                if (startTime1 == null && startTime2 != null) {
                    return sortAscending ? -1 : 1;
                }
                if (startTime2 == null && startTime1 != null) {
                    return sortAscending ? 1 : -1;
                }

                if (startTime1 == null && startTime2 == null || startTime1.equals(startTime2)) {
                    return getTitleComparator(sortAscending).compare(section1, section2);
                }
                return sortAscending ? startTime1.compareTo(startTime2) : startTime2.compareTo(startTime1);
            } else {
                return categoryNameComparison;
            }
        }
    };
}

From source file:org.sakaiproject.tool.section.jsf.backingbean.AddSectionsBean.java

/**
 * As part of the crutch for JSF's inability to do validation on relative
 * values in different components, this method checks whether two times, as
 * expressed by string start and end times and booleans indicating am/pm,
 * express times where the end time proceeds a start time.
 * // w  ww  .j ava 2s .  co  m
 * @param meeting
 * @return
 */
public static boolean isEndTimeBeforeStartTime(LocalMeetingModel meeting) {
    String startTime = null;
    if (!meeting.isStartTimeDefault()) {
        startTime = meeting.getStartTimeString();
    }

    String endTime = null;
    if (!meeting.isEndTimeDefault()) {
        endTime = meeting.getEndTimeString();
    }

    boolean startTimeAm = meeting.isStartTimeAm();
    boolean endTimeAm = meeting.isEndTimeAm();

    if (StringUtils.trimToNull(startTime) != null && StringUtils.trimToNull(endTime) != null) {
        Time start = JsfUtil.convertStringToTime(startTime, startTimeAm);
        Time end = JsfUtil.convertStringToTime(endTime, endTimeAm);
        if (start.after(end)) {
            if (log.isDebugEnabled())
                log.debug("You can not set an end time earlier than the start time.");
            return true;
        }
    }

    if (StringUtils.trimToNull(startTime) != null && StringUtils.trimToNull(endTime) != null) {
        Time start = JsfUtil.convertStringToTime(startTime, startTimeAm);
        Time end = JsfUtil.convertStringToTime(endTime, endTimeAm);
        if (start.equals(end)) {
            if (log.isDebugEnabled())
                log.debug("You can not set an end time that same as start time.");
            return true;
        }
    }
    return false;
}