List of usage examples for java.sql Time Time
public Time(long time)
Time
object using a milliseconds time value. From source file:cn.afterturn.easypoi.excel.imports.CellValueService.java
/** * ??//from w w w . j a v a 2 s.co m * * @param cell * @param entity * @return */ private Object getCellValue(String classFullName, Cell cell, ExcelImportEntity entity) { if (cell == null) { return ""; } Object result = null; if ("class java.util.Date".equals(classFullName) || "class java.sql.Date".equals(classFullName) || ("class java.sql.Time").equals(classFullName) || ("class java.time.Instant").equals(classFullName) || ("class java.time.LocalDate").equals(classFullName) || ("class java.time.LocalDateTime").equals(classFullName) || ("class java.sql.Timestamp").equals(classFullName)) { //FIX: ?yyyyMMdd cell.getDateCellValue() ? if (CellType.NUMERIC == cell.getCellType() && DateUtil.isCellDateFormatted(cell)) { result = DateUtil.getJavaDate(cell.getNumericCellValue()); } else { String val = ""; try { val = cell.getStringCellValue(); } catch (Exception e) { cell.setCellType(CellType.STRING); val = cell.getStringCellValue(); } result = getDateData(entity, val); if (result == null) { return null; } } if (("class java.time.Instant").equals(classFullName)) { result = ((Date) result).toInstant(); } else if (("class java.time.LocalDate").equals(classFullName)) { result = ((Date) result).toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); } else if (("class java.time.LocalDateTime").equals(classFullName)) { result = ((Date) result).toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); } else if (("class java.sql.Date").equals(classFullName)) { result = new java.sql.Date(((Date) result).getTime()); } else if (("class java.sql.Time").equals(classFullName)) { result = new Time(((Date) result).getTime()); } else if (("class java.sql.Timestamp").equals(classFullName)) { result = new Timestamp(((Date) result).getTime()); } } else { switch (cell.getCellType()) { case STRING: result = cell.getRichStringCellValue() == null ? "" : cell.getRichStringCellValue().getString(); break; case NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { if ("class java.lang.String".equals(classFullName)) { result = formateDate(entity, cell.getDateCellValue()); } } else { result = readNumericCell(cell); } break; case BOOLEAN: result = Boolean.toString(cell.getBooleanCellValue()); break; case BLANK: break; case ERROR: break; case FORMULA: try { result = readNumericCell(cell); } catch (Exception e1) { try { result = cell.getRichStringCellValue() == null ? "" : cell.getRichStringCellValue().getString(); } catch (Exception e2) { throw new RuntimeException("???", e2); } } break; default: break; } } return result; }
From source file:org.kuali.kpme.core.calendar.entry.CalendarEntryBo.java
public Time getBeginPeriodTime() { return beginPeriodDateTime != null ? new Time(beginPeriodDateTime.getTime()) : null; }
From source file:org.jabsorb.ng.serializer.impl.DateSerializer.java
@Override public Object unmarshall(final SerializerState state, Class<?> clazz, final Object o) throws UnmarshallException { final JSONObject jso = (JSONObject) o; long time;/* www. ja v a2s . c o m*/ try { time = jso.getLong("time"); } catch (final JSONException e) { throw new UnmarshallException("Could not get the time in date serialiser", e); } if (jso.has("javaClass")) { try { clazz = Class.forName(jso.getString("javaClass")); } catch (final ClassNotFoundException e) { throw new UnmarshallException(e.getMessage(), e); } catch (final JSONException e) { throw new UnmarshallException("Could not find javaClass", e); } } Object returnValue = null; if (Date.class.equals(clazz)) { returnValue = new Date(time); } else if (Timestamp.class.equals(clazz)) { returnValue = new Timestamp(time); } else if (java.sql.Date.class.equals(clazz)) { returnValue = new java.sql.Date(time); } else if (java.sql.Time.class.equals(clazz)) { returnValue = new Time(time); } if (returnValue == null) { throw new UnmarshallException("invalid class " + clazz); } state.setSerialized(o, returnValue); return returnValue; }
From source file:com.alibaba.wasp.jdbc.TestPreparedStatement.java
public void testDateTimeTimestampWithCalendar() throws SQLException { Statement stat = conn.createStatement(); stat.execute("create table ts(x timestamp primary key)"); stat.execute("create table t(x time primary key)"); stat.execute("create table d(x date)"); Calendar utcCalendar = new GregorianCalendar(new SimpleTimeZone(0, "Z")); TimeZone old = TimeZone.getDefault(); DateTimeUtils.resetCalendar();/*from w w w. j a v a2 s . co m*/ TimeZone.setDefault(TimeZone.getTimeZone("PST")); try { Timestamp ts1 = Timestamp.valueOf("2010-03-13 18:15:00"); Time t1 = new Time(ts1.getTime()); Date d1 = new Date(ts1.getTime()); // when converted to UTC, this is 03:15, which doesn't actually exist // because of summer time change at that day Timestamp ts2 = Timestamp.valueOf("2010-03-13 19:15:00"); Time t2 = new Time(ts2.getTime()); Date d2 = new Date(ts2.getTime()); PreparedStatement prep; ResultSet rs; prep = conn.prepareStatement("insert into ts values(?)"); prep.setTimestamp(1, ts1, utcCalendar); prep.execute(); prep.setTimestamp(1, ts2, utcCalendar); prep.execute(); prep = conn.prepareStatement("insert into t values(?)"); prep.setTime(1, t1, utcCalendar); prep.execute(); prep.setTime(1, t2, utcCalendar); prep.execute(); prep = conn.prepareStatement("insert into d values(?)"); prep.setDate(1, d1, utcCalendar); prep.execute(); prep.setDate(1, d2, utcCalendar); prep.execute(); rs = stat.executeQuery("select * from ts order by x"); rs.next(); assertEquals("2010-03-14 02:15:00.0", rs.getString(1)); assertEquals("2010-03-13 18:15:00.0", rs.getTimestamp(1, utcCalendar).toString()); assertEquals("2010-03-14 03:15:00.0", rs.getTimestamp(1).toString()); assertEquals("2010-03-14 02:15:00.0", rs.getString("x")); assertEquals("2010-03-13 18:15:00.0", rs.getTimestamp("x", utcCalendar).toString()); assertEquals("2010-03-14 03:15:00.0", rs.getTimestamp("x").toString()); rs.next(); assertEquals("2010-03-14 03:15:00.0", rs.getString(1)); assertEquals("2010-03-13 19:15:00.0", rs.getTimestamp(1, utcCalendar).toString()); assertEquals("2010-03-14 03:15:00.0", rs.getTimestamp(1).toString()); assertEquals("2010-03-14 03:15:00.0", rs.getString("x")); assertEquals("2010-03-13 19:15:00.0", rs.getTimestamp("x", utcCalendar).toString()); assertEquals("2010-03-14 03:15:00.0", rs.getTimestamp("x").toString()); rs = stat.executeQuery("select * from t order by x"); rs.next(); assertEquals("02:15:00", rs.getString(1)); assertEquals("18:15:00", rs.getTime(1, utcCalendar).toString()); assertEquals("02:15:00", rs.getTime(1).toString()); assertEquals("02:15:00", rs.getString("x")); assertEquals("18:15:00", rs.getTime("x", utcCalendar).toString()); assertEquals("02:15:00", rs.getTime("x").toString()); rs.next(); assertEquals("03:15:00", rs.getString(1)); assertEquals("19:15:00", rs.getTime(1, utcCalendar).toString()); assertEquals("03:15:00", rs.getTime(1).toString()); assertEquals("03:15:00", rs.getString("x")); assertEquals("19:15:00", rs.getTime("x", utcCalendar).toString()); assertEquals("03:15:00", rs.getTime("x").toString()); rs = stat.executeQuery("select * from d order by x"); rs.next(); assertEquals("2010-03-14", rs.getString(1)); assertEquals("2010-03-13", rs.getDate(1, utcCalendar).toString()); assertEquals("2010-03-14", rs.getDate(1).toString()); assertEquals("2010-03-14", rs.getString("x")); assertEquals("2010-03-13", rs.getDate("x", utcCalendar).toString()); assertEquals("2010-03-14", rs.getDate("x").toString()); rs.next(); assertEquals("2010-03-14", rs.getString(1)); assertEquals("2010-03-13", rs.getDate(1, utcCalendar).toString()); assertEquals("2010-03-14", rs.getDate(1).toString()); assertEquals("2010-03-14", rs.getString("x")); assertEquals("2010-03-13", rs.getDate("x", utcCalendar).toString()); assertEquals("2010-03-14", rs.getDate("x").toString()); } finally { TimeZone.setDefault(old); DateTimeUtils.resetCalendar(); } stat.execute("drop table ts"); stat.execute("drop table t"); stat.execute("drop table d"); }
From source file:org.apache.phoenix.util.DateUtil.java
public static Time parseTime(String timeValue) { return new Time(parseDateTime(timeValue)); }
From source file:com.kenshoo.freemarker.util.DataModelParser.java
private static Object parseValue(String value, TimeZone timeZone) throws DataModelParsingException { // Note: Because we fall back to interpret the input as a literal string value when it doesn't look like // anything else (like a number, boolean, etc.), it's important to avoid misunderstandings, and throw exception // in suspicious situations. The user can always quote the string value if we are "too smart". But he will // be confused about the rules of FreeMarker if what he believes to be a non-string is misinterpreted by this // parser as a string. Getting sometimes an error and then quoting the string is better than that. if (value.endsWith(";")) { // Tolerate this habit of Java and JavaScript programmers value = value.substring(value.length() - 1).trim(); }/* w ww. j ava 2 s.c om*/ if (NUMBER_LIKE.matcher(value).matches()) { try { return new BigDecimal(value); } catch (NumberFormatException e) { // Maybe it's a ISO 8601 Date/time/datetime CalendarFieldsToDateConverter calToDateConverter = new TrivialCalendarFieldsToDateConverter(); DateParseException attemptedTemportalPExc = null; String attemptedTemporalType = null; final int dashIdx = value.indexOf('-'); final int colonIdx = value.indexOf(':'); if (value.indexOf('T') > 1 || (dashIdx > 1 && colonIdx > dashIdx)) { try { return new Timestamp( DateUtil.parseISO8601DateTime(value, timeZone, calToDateConverter).getTime()); } catch (DateParseException pExc) { attemptedTemporalType = "date-time"; attemptedTemportalPExc = pExc; } } else if (dashIdx > 1) { try { return new java.sql.Date( DateUtil.parseISO8601Date(value, timeZone, calToDateConverter).getTime()); } catch (DateParseException pExc) { attemptedTemporalType = "date"; attemptedTemportalPExc = pExc; } } else if (colonIdx > 1) { try { return new Time(DateUtil.parseISO8601Time(value, timeZone, calToDateConverter).getTime()); } catch (DateParseException pExc) { attemptedTemporalType = "time"; attemptedTemportalPExc = pExc; } } if (attemptedTemportalPExc == null) { throw new DataModelParsingException("Malformed number: " + value, e); } else { throw new DataModelParsingException("Malformed ISO 8601 " + attemptedTemporalType + " (or malformed number): " + attemptedTemportalPExc.getMessage(), e.getCause()); } } } else if (value.startsWith("\"")) { try { return JSON_MAPPER.readValue(value, String.class); } catch (IOException e) { throw new DataModelParsingException( "Malformed quoted string (using JSON syntax): " + getMessageWithoutLocation(e), e); } } else if (value.startsWith("\'")) { throw new DataModelParsingException( "Malformed quoted string (using JSON syntax): Use \" character for quotation, not \' character."); } else if (value.startsWith("[")) { try { return JSON_MAPPER.readValue(value, List.class); } catch (IOException e) { throw new DataModelParsingException( "Malformed list (using JSON syntax): " + getMessageWithoutLocation(e), e); } } else if (value.startsWith("{")) { try { return JSON_MAPPER.readValue(value, LinkedHashMap.class); } catch (IOException e) { throw new DataModelParsingException( "Malformed list (using JSON syntax): " + getMessageWithoutLocation(e), e); } } else if (value.startsWith("<")) { try { DocumentBuilder builder = NodeModel.getDocumentBuilderFactory().newDocumentBuilder(); ErrorHandler errorHandler = NodeModel.getErrorHandler(); if (errorHandler != null) builder.setErrorHandler(errorHandler); final Document doc = builder.parse(new InputSource(new StringReader(value))); NodeModel.simplify(doc); return doc; } catch (SAXException e) { final String saxMsg = e.getMessage(); throw new DataModelParsingException("Malformed XML: " + (saxMsg != null ? saxMsg : e), e); } catch (Exception e) { throw new DataModelParsingException("XML parsing has failed with internal error: " + e, e); } } else if (value.equalsIgnoreCase(KEYWORD_TRUE)) { checkKeywordCase(value, KEYWORD_TRUE); return Boolean.TRUE; } else if (value.equalsIgnoreCase(KEYWORD_FALSE)) { checkKeywordCase(value, KEYWORD_FALSE); return Boolean.FALSE; } else if (value.equalsIgnoreCase(KEYWORD_NULL)) { checkKeywordCase(value, KEYWORD_NULL); return null; } else if (value.equalsIgnoreCase(KEYWORD_NAN)) { checkKeywordCase(value, KEYWORD_NAN); return Double.NaN; } else if (value.equalsIgnoreCase(KEYWORD_INFINITY)) { checkKeywordCase(value, KEYWORD_INFINITY); return Double.POSITIVE_INFINITY; } else if (value.equalsIgnoreCase(KEYWORD_POSITIVE_INFINITY)) { checkKeywordCase(value, KEYWORD_POSITIVE_INFINITY); return Double.POSITIVE_INFINITY; } else if (value.equalsIgnoreCase(KEYWORD_NEGATIVE_INFINITY)) { checkKeywordCase(value, KEYWORD_NEGATIVE_INFINITY); return Double.NEGATIVE_INFINITY; } else if (value.length() == 0) { throw new DataModelParsingException( "Empty value. (If you indeed wanted a 0 length string, quote it, like \"\".)"); } else { return value; } }
From source file:com.taobao.adfs.database.tdhsocket.client.response.TDHSResutSet.java
public Time getTime(int columnIndex) throws SQLException { Long time = ConvertUtil.getTimeFromString(this.getString(columnIndex), null); return time == null ? null : new Time(time); }
From source file:org.jumpmind.db.sql.Row.java
public Time getTime(String columnName) { Object obj = this.get(columnName); if (obj instanceof Time) { return (Time) obj; } else {/*from ww w.jav a 2s . c om*/ Date date = getDateTime(columnName); return new Time(date.getTime()); } }
From source file:org.omnaest.utils.table.impl.adapter.TableToResultSetAdapter.java
@Override public Time getTime(int columnIndex) throws SQLException { return new Time(this.getLong(columnIndex)); }
From source file:org.kuali.kpme.core.calendar.CalendarBo.java
public static CalendarBo from(Calendar im) { if (im == null) { return null; }//from ww w.j a v a 2s . c o m CalendarBo cal = new CalendarBo(); cal.setHrCalendarId(im.getHrCalendarId()); cal.setCalendarName(im.getCalendarName()); cal.setCalendarDescriptions(im.getCalendarDescriptions()); cal.setFlsaBeginDay(im.getFlsaBeginDay()); cal.setFlsaBeginTime(im.getFlsaBeginLocalTime() == null ? null : new Time(im.getFlsaBeginLocalTime().toDateTimeToday().getMillis())); cal.setCalendarTypes(im.getCalendarTypes()); cal.setFlsaBeginDayConstant(im.getFlsaBeginDayConstant()); cal.setVersionNumber(im.getVersionNumber()); cal.setObjectId(im.getObjectId()); return cal; }