List of usage examples for java.sql Time Time
public Time(long time)
Time
object using a milliseconds time value. From source file:org.sakaiproject.coursemanagement.test.CourseManagementAdministrationTest.java
@Test public void testMeetingCascading() throws Exception { // Create a course offering cmAdmin.createAcademicSession("as1", "academic session 1", "an academic session", new Date(), new Date()); cmAdmin.createCanonicalCourse("cc1", "cc 1", "a canon course"); cmAdmin.createCourseOffering("co1", "course 1", "course", "open", "as1", "cc1", null, null); // Add a section Section section1 = cmAdmin.createSection("sec1", "sec1", "sec1", "sec1", null, "co1", null); // Add some meetings for the section Meeting meeting1 = cmAdmin.newSectionMeeting("sec1", "a lecture hall", new Time(new Date().getTime()), new Time(new Date().getTime()), "If you're late, I won't let you in."); section1.getMeetings().add(meeting1); // Update the section cmAdmin.updateSection(section1);/* ww w . j a v a 2 s .c o m*/ // Ensure that the section has the right meetings Section section2 = cm.getSection("sec1"); Assert.assertEquals(1, section2.getMeetings().size()); Assert.assertEquals("a lecture hall", ((Meeting) section2.getMeetings().iterator().next()).getLocation()); }
From source file:com.redhat.jenkins.plugins.ci.messaging.ActiveMqMessagingWorker.java
private static String formatHeaders(Message message) { Destination dest = null;//from w w w. j a v a 2 s. c o m int delMode = 0; long expiration = 0; Time expTime = null; int priority = 0; String msgID = null; long timestamp = 0; Time timestampTime = null; String correlID = null; Destination replyTo = null; boolean redelivered = false; String type = null; StringBuilder sb = new StringBuilder(); try { try { dest = message.getJMSDestination(); sb.append(" JMSDestination: "); sb.append(dest); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSDestination header\n", e); } try { delMode = message.getJMSDeliveryMode(); if (delMode == DeliveryMode.NON_PERSISTENT) { sb.append(" JMSDeliveryMode: non-persistent\n"); } else if (delMode == DeliveryMode.PERSISTENT) { sb.append(" JMSDeliveryMode: persistent\n"); } else { sb.append(" JMSDeliveryMode: neither persistent nor non-persistent; error\n"); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSDeliveryMode header\n", e); } try { expiration = message.getJMSExpiration(); if (expiration != 0) { expTime = new Time(expiration); sb.append(" JMSExpiration: "); sb.append(expTime); sb.append("\n"); } else { sb.append(" JMSExpiration: 0\n"); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSExpiration header\n", e); } try { priority = message.getJMSPriority(); sb.append(" JMSPriority: "); sb.append(priority); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSPriority header\n", e); } try { msgID = message.getJMSMessageID(); sb.append(" JMSMessageID: "); sb.append(msgID); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSMessageID header\n", e); } try { timestamp = message.getJMSTimestamp(); if (timestamp != 0) { timestampTime = new Time(timestamp); sb.append(" JMSTimestamp: "); sb.append(timestampTime); sb.append("\n"); } else { sb.append(" JMSTimestamp: 0\n"); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSTimestamp header\n", e); } try { correlID = message.getJMSCorrelationID(); sb.append(" JMSCorrelationID: "); sb.append(correlID); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSCorrelationID header\n", e); } try { replyTo = message.getJMSReplyTo(); sb.append(" JMSReplyTo: "); sb.append(replyTo); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSReplyTo header\n", e); } try { redelivered = message.getJMSRedelivered(); sb.append(" JMSRedelivered: "); sb.append(redelivered); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSRedelivered header\n", e); } try { type = message.getJMSType(); sb.append(" JMSType: "); sb.append(type); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSType header\n", e); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMS headers\n", e); } return sb.toString(); }
From source file:org.sakaiproject.coursemanagement.impl.SampleDataLoader.java
protected Time getTime(String timeString) { Date date = null;//w w w .java 2s . co m try { date = sdf().parse(timeString); } catch (ParseException pe) { log.error("Can not parse time " + timeString); date = new Date(); } return new Time(date.getTime()); }
From source file:adalid.commons.util.TimeUtils.java
public static java.util.Date parse(String pdq) { if (StringUtils.isBlank(pdq)) { return null; }// w w w . j a va2s. c o m String string = pdq.trim(); ParsePosition position = new ParsePosition(0); java.util.Date util = timestampFormatter().parse(string, position); int i = position.getIndex(); int l = string.length(); if (util != null && i == l) { return new Timestamp(util.getTime()); } position.setIndex(0); util = dateFormatter().parse(string, position); i = position.getIndex(); if (util != null) { if (i == l) { return new Date(util.getTime()); } java.util.Date time = timeFormatter().parse(string, position); i = position.getIndex(); if (time != null && i == l) { return merge(util, time); } } position.setIndex(0); util = timeFormatter().parse(string, position); i = position.getIndex(); if (util != null && i == l) { return new Time(util.getTime()); } return null; }
From source file:org.seasar.cubby.internal.controller.impl.RequestParameterBinderImplTest.java
@Test public void converters() { final Map<String, Object[]> map = new HashMap<String, Object[]>(); map.put("decimal", new Object[] { "12.3" }); map.put("decimals", new Object[] { "45.6", "78.9" }); map.put("bigint", new Object[] { "9876" }); map.put("bigints", new Object[] { "5432", "10" }); map.put("bool1", new Object[] { "true" }); map.put("bools1", new Object[] { "true", "false" }); map.put("bool2", new Object[] { "false" }); map.put("bools2", new Object[] { "false", "true", "false" }); map.put("byte1", new Object[] { "12" }); map.put("bytes1", new Object[] { "34", "56" }); map.put("byte2", new Object[] { "98" }); map.put("bytes2", new Object[] { "76", "54" }); map.put("char1", new Object[] { "a" }); map.put("chars1", new Object[] { "b", "c" }); map.put("char2", new Object[] { "d" }); map.put("chars2", new Object[] { "e", "f" }); map.put("date", new Object[] { "2008-7-28" }); map.put("dates", new Object[] { "2008-8-14", "2008-10-30" }); map.put("double1", new Object[] { "1.2" }); map.put("doubles1", new Object[] { "3.4", "5.6" }); map.put("double2", new Object[] { "9.8" }); map.put("doubles2", new Object[] { "7.6", "5.4" }); map.put("en", new Object[] { "VALUE1" }); map.put("ens", new Object[] { "VALUE2", "VALUE3" }); map.put("float1", new Object[] { "1.2" }); map.put("floats1", new Object[] { "3.4", "5.6" }); map.put("float2", new Object[] { "9.8" }); map.put("floats2", new Object[] { "7.6", "5.4" }); map.put("int1", new Object[] { "12" }); map.put("ints1", new Object[] { "34", "56" }); map.put("int2", new Object[] { "98" }); map.put("ints2", new Object[] { "76", "54" }); map.put("long1", new Object[] { "12" }); map.put("longs1", new Object[] { "34", "56" }); map.put("long2", new Object[] { "98" }); map.put("longs2", new Object[] { "76", "54" }); map.put("short1", new Object[] { "12" }); map.put("shorts1", new Object[] { "34", "56" }); map.put("short2", new Object[] { "98" }); map.put("shorts2", new Object[] { "76", "54" }); map.put("sqldate", new Object[] { "2008-7-28" }); map.put("sqldates", new Object[] { "2008-8-14", "2008-10-30" }); map.put("sqltime", new Object[] { "12:34:56" }); map.put("sqltimes", new Object[] { "13:45:24", "23:44:00" }); map.put("sqltimestamp", new Object[] { "2008-7-28 12:34:56" }); map.put("sqltimestamps", new Object[] { "2008-8-14 13:45:24", "2008-10-30 23:44:00" }); final ConvertersDto dto = new ConvertersDto(); final ActionContext actionContext = new MockActionContext(null, MockAction.class, actionMethod(MockAction.class, "all")); final List<ConversionFailure> conversionFailures = requestParameterBinder.bind(map, dto, actionContext); assertNotNull(dto.getDecimal());//from www.jav a 2 s. c o m assertTrue(new BigDecimal("12.3").compareTo(dto.getDecimal()) == 0); assertNotNull(dto.getDecimals()); assertEquals(2, dto.getDecimals().length); assertTrue(new BigDecimal("45.6").compareTo(dto.getDecimals()[0]) == 0); assertTrue(new BigDecimal("78.9").compareTo(dto.getDecimals()[1]) == 0); assertNotNull(dto.getBigint()); assertTrue(new BigInteger("9876").compareTo(dto.getBigint()) == 0); assertNotNull(dto.getBigints()); assertEquals(2, dto.getBigints().length); assertTrue(new BigInteger("5432").compareTo(dto.getBigints()[0]) == 0); assertTrue(new BigInteger("10").compareTo(dto.getBigints()[1]) == 0); assertNotNull(dto.getBool1()); assertTrue(dto.getBool1()); assertNotNull(dto.getBools1()); assertEquals(2, dto.getBools1().length); assertTrue(dto.getBools1()[0]); assertFalse(dto.getBools1()[1]); assertFalse(dto.isBool2()); assertNotNull(dto.getBools2()); assertEquals(3, dto.getBools2().length); assertFalse(dto.getBools2()[0]); assertTrue(dto.getBools2()[1]); assertFalse(dto.getBools2()[2]); assertNotNull(dto.getByte1()); assertEquals(Byte.valueOf((byte) 12), dto.getByte1()); assertNotNull(dto.getBytes1()); assertEquals(2, dto.getBytes1().length); assertEquals(Byte.valueOf((byte) 34), dto.getBytes1()[0]); assertEquals(Byte.valueOf((byte) 56), dto.getBytes1()[1]); assertEquals((byte) 98, dto.getByte2()); assertNotNull(dto.getBytes2()); assertEquals(2, dto.getBytes2().length); assertEquals((byte) 76, dto.getBytes2()[0]); assertEquals((byte) 54, dto.getBytes2()[1]); assertNotNull(dto.getChar1()); assertEquals(Character.valueOf('a'), dto.getChar1()); assertNotNull(dto.getChars1()); assertEquals(2, dto.getChars1().length); assertEquals(Character.valueOf('b'), dto.getChars1()[0]); assertEquals(Character.valueOf('c'), dto.getChars1()[1]); assertNotNull(dto.getChar2()); assertEquals('d', dto.getChar2()); assertNotNull(dto.getChars2()); assertEquals(2, dto.getChars2().length); assertEquals('e', dto.getChars2()[0]); assertEquals('f', dto.getChars2()[1]); assertNotNull(dto.getDate()); assertEquals(new Date(fromDateToMillis(2008, 7, 28)), dto.getDate()); assertNotNull(dto.getDates()); assertEquals(2, dto.getDates().length); assertEquals(new Date(fromDateToMillis(2008, 8, 14)), dto.getDates()[0]); assertEquals(new Date(fromDateToMillis(2008, 10, 30)), dto.getDates()[1]); assertNotNull(dto.getDouble1()); assertEquals(new Double(1.2d), dto.getDouble1()); assertNotNull(dto.getDoubles1()); assertEquals(2, dto.getDoubles1().length); assertEquals(new Double(3.4d), dto.getDoubles1()[0]); assertEquals(new Double(5.6d), dto.getDoubles1()[1]); assertEquals(9.8d, dto.getDouble2(), 0.0d); assertNotNull(dto.getDoubles2()); assertEquals(2, dto.getDoubles2().length); assertEquals(7.6d, dto.getDoubles2()[0], 0.0d); assertEquals(5.4d, dto.getDoubles2()[1], 0.0d); assertNotNull(dto.getEn()); assertSame(ExEnum.VALUE1, dto.getEn()); assertNotNull(dto.getEns()); assertEquals(2, dto.getEns().length); assertSame(ExEnum.VALUE2, dto.getEns()[0]); assertSame(ExEnum.VALUE3, dto.getEns()[1]); assertNotNull(dto.getFloat1()); assertEquals(new Float(1.2f), dto.getFloat1()); assertNotNull(dto.getFloats1()); assertEquals(2, dto.getFloats1().length); assertEquals(new Float(3.4f), dto.getFloats1()[0]); assertEquals(new Float(5.6f), dto.getFloats1()[1]); assertEquals(9.8f, dto.getFloat2(), 0.0f); assertNotNull(dto.getFloats2()); assertEquals(2, dto.getFloats2().length); assertEquals(7.6f, dto.getFloats2()[0], 0.0f); assertEquals(5.4f, dto.getFloats2()[1], 0.0f); assertNotNull(dto.getInt1()); assertEquals(Integer.valueOf(12), dto.getInt1()); assertNotNull(dto.getInts1()); assertEquals(2, dto.getInts1().length); assertEquals(Integer.valueOf(34), dto.getInts1()[0]); assertEquals(Integer.valueOf(56), dto.getInts1()[1]); assertEquals(98, dto.getInt2()); assertNotNull(dto.getInts2()); assertEquals(2, dto.getInts2().length); assertEquals(76, dto.getInts2()[0]); assertEquals(54, dto.getInts2()[1]); assertNotNull(dto.getLong1()); assertEquals(Long.valueOf(12l), dto.getLong1()); assertNotNull(dto.getLongs1()); assertEquals(2, dto.getLongs1().length); assertEquals(Long.valueOf(34l), dto.getLongs1()[0]); assertEquals(Long.valueOf(56l), dto.getLongs1()[1]); assertEquals(98l, dto.getLong2()); assertNotNull(dto.getLongs2()); assertEquals(2, dto.getLongs2().length); assertEquals(76l, dto.getLongs2()[0]); assertEquals(54l, dto.getLongs2()[1]); assertNotNull(dto.getShort1()); assertEquals(Short.valueOf((short) 12), dto.getShort1()); assertNotNull(dto.getShorts1()); assertEquals(2, dto.getShorts1().length); assertEquals(Short.valueOf((short) 34), dto.getShorts1()[0]); assertEquals(Short.valueOf((short) 56), dto.getShorts1()[1]); assertEquals((short) 98, dto.getShort2()); assertNotNull(dto.getShorts2()); assertEquals(2, dto.getShorts2().length); assertEquals((short) 76, dto.getShorts2()[0]); assertEquals((short) 54, dto.getShorts2()[1]); assertNotNull(dto.getSqldate()); assertEquals(new java.sql.Date(fromDateToMillis(2008, 7, 28)), dto.getSqldate()); assertNotNull(dto.getSqldates()); assertEquals(2, dto.getSqldates().length); assertEquals(new java.sql.Date(fromDateToMillis(2008, 8, 14)), dto.getSqldates()[0]); assertEquals(new java.sql.Date(fromDateToMillis(2008, 10, 30)), dto.getSqldates()[1]); assertNotNull(dto.getSqltime()); assertEquals(new Time(fromTimeToMillis(12, 34, 56)), dto.getSqltime()); assertNotNull(dto.getSqltimes()); assertEquals(2, dto.getSqltimes().length); assertEquals(new Time(fromTimeToMillis(13, 45, 24)), dto.getSqltimes()[0]); assertEquals(new Time(fromTimeToMillis(23, 44, 00)), dto.getSqltimes()[1]); assertNotNull(dto.getSqltimestamp()); assertEquals(new Timestamp(fromTimestampToMillis(2008, 7, 28, 12, 34, 56)), dto.getSqltimestamp()); assertNotNull(dto.getSqltimestamps()); assertEquals(2, dto.getSqltimestamps().length); assertEquals(new Timestamp(fromTimestampToMillis(2008, 8, 14, 13, 45, 24)), dto.getSqltimestamps()[0]); assertEquals(new Timestamp(fromTimestampToMillis(2008, 10, 30, 23, 44, 00)), dto.getSqltimestamps()[1]); assertTrue(conversionFailures.isEmpty()); System.out.println(dto); }
From source file:com.haulmont.cuba.web.gui.components.WebDateField.java
protected Date constructDate() { final Date datePickerDate = dateField.getValue(); if (datePickerDate == null) { return null; }/*from ww w . ja v a 2 s . com*/ Calendar dateCalendar = Calendar.getInstance(userSession.getLocale()); if (timeZone != null) { dateCalendar.setTimeZone(timeZone); } dateCalendar.setTime(datePickerDate); if (timeField.getValue() == null) { dateCalendar.set(Calendar.HOUR_OF_DAY, 0); dateCalendar.set(Calendar.MINUTE, 0); dateCalendar.set(Calendar.SECOND, 0); } else { Calendar timeCalendar = Calendar.getInstance(userSession.getLocale()); timeCalendar.setTime(timeField.<Date>getValue()); dateCalendar.set(Calendar.HOUR_OF_DAY, timeCalendar.get(Calendar.HOUR_OF_DAY)); dateCalendar.set(Calendar.MINUTE, timeCalendar.get(Calendar.MINUTE)); dateCalendar.set(Calendar.SECOND, timeCalendar.get(Calendar.SECOND)); } Date resultDate = dateCalendar.getTime(); if (metaProperty != null) { Class javaClass = metaProperty.getRange().asDatatype().getJavaClass(); if (javaClass.equals(java.sql.Date.class)) { return new java.sql.Date(resultDate.getTime()); } else if (javaClass.equals(Time.class)) { return new Time(resultDate.getTime()); } else { return resultDate; } } else { return resultDate; } }
From source file:org.wso2.carbon.dataservices.core.DBUtils.java
/** * Create a Time object from the given time string. *//*from w w w.ja v a2 s.c o m*/ public static Time getTime(String value) throws DataServiceFault, ParseException { if (value == null || value.isEmpty()) { throw new DataServiceFault("Empty string or null value was found as time."); } return new Time(ConverterUtil.convertToTime(value).getAsCalendar().getTimeInMillis()); }
From source file:ips1ap101.lib.base.util.StrUtils.java
public static Object getObjeto(String string, Class<?> clazz) { if (string == null || clazz == null) { return null; }/*from w ww . ja v a 2s . c om*/ try { String value = StringUtils.trimToNull(string); if (value == null) { return null; } else if (Character.class.isAssignableFrom(clazz)) { return new Character(value.charAt(0)); } else if (String.class.isAssignableFrom(clazz)) { // ALFANUMERICO return string; } else if (Boolean.class.isAssignableFrom(clazz)) { return BitUtils.valueOf(value); } else if (Byte.class.isAssignableFrom(clazz)) { return new Byte(new BigDecimal(value).byteValue()); } else if (Short.class.isAssignableFrom(clazz)) { return new Short(new BigDecimal(value).shortValue()); } else if (Integer.class.isAssignableFrom(clazz)) { // ENTERO return new Integer(new BigDecimal(value).intValue()); } else if (Long.class.isAssignableFrom(clazz)) { return new Long(new BigDecimal(value).longValue()); } else if (Float.class.isAssignableFrom(clazz)) { return new Float(new BigDecimal(value).floatValue()); } else if (Double.class.isAssignableFrom(clazz)) { return new Double(new BigDecimal(value).doubleValue()); } else if (BigInteger.class.isAssignableFrom(clazz)) { // ENTERO_GRANDE return new Long(new BigDecimal(value).longValue()); } else if (BigDecimal.class.isAssignableFrom(clazz)) { // NUMERICO return new BigDecimal(value); } else if (java.util.Date.class.isAssignableFrom(clazz)) { // FECHA_HORA java.util.Date dateTime = TimeUtils.parse(value); if (Timestamp.class.isAssignableFrom(clazz)) { return new Timestamp(dateTime.getTime()); } else if (Time.class.isAssignableFrom(clazz)) { return new Time(dateTime.getTime()); } else if (Date.class.isAssignableFrom(clazz)) { return new Date(dateTime.getTime()); } else { return dateTime; } } // } catch (NumberFormatException e) { // return null; } catch (RuntimeException e) { return null; } return null; }
From source file:adalid.commons.util.TimeUtils.java
public static Time addTime(java.util.Date date, int addend, char unit) { if (date == null) { return null; }//from ww w.j a v a2s . c o m Calendar c = newTimeCalendar(date); if (addend != 0) { switch (unit) { case 'h': c.add(Calendar.HOUR, addend); break; case 'm': c.add(Calendar.MINUTE, addend); break; case 's': c.add(Calendar.SECOND, addend); break; default: break; } } return new Time(c.getTimeInMillis()); }
From source file:com.taobao.adfs.database.tdhsocket.client.response.TDHSResutSet.java
public Time getTime(int columnIndex, Calendar cal) throws SQLException { Long time = ConvertUtil.getTimeFromString(this.getString(columnIndex), cal); return time == null ? null : new Time(time); }