@Override public Value negate() { return ValueTime.fromNanos(-nanos); }
@Override public void write(DataBuffer buff, Object obj) { Time t = (Time) obj; writeValue(buff, ValueTime.get(t)); }
return ValueTime.fromNanos(0); case TIMESTAMP: return ValueTime.fromNanos(((ValueTimestamp) this).getNanos()); switch (getType()) { case TIME: return DateTimeUtils.normalizeTimestamp(0, ((ValueTime) this).getNanos()); case DATE: return ValueTimestamp.fromDateValueAndNanos(((ValueDate) this).getDateValue(), 0); return ValueDecimal.get(new BigDecimal(s.trim())); case TIME: return ValueTime.parse(s.trim()); case DATE: return ValueDate.parse(s.trim());
/** * Convert the time to the specified time zone. * * @param value the time (might be ValueNull) * @param calendar the calendar * @return the time using the correct time zone */ public static Time convertTime(Value value, Calendar calendar) { if (value == ValueNull.INSTANCE) { return null; } ValueTime t = (ValueTime) value.convertTo(Value.TIME); Calendar cal = (Calendar) calendar.clone(); cal.clear(); cal.setLenient(true); long nanos = t.getNanos(); long millis = nanos / 1000000; nanos -= millis * 1000000; long s = millis / 1000; millis -= s * 1000; long m = s / 60; s -= m * 60; long h = m / 60; m -= h * 60; setCalendarFields(cal, 1970, 1, 1, (int) h, (int) m, (int) s, (int) millis); long ms = cal.getTimeInMillis(); return new Time(ms); }
String time = currentValue.getString(); read(); r = ValueExpression.get(ValueTime.parse(time)); } else if (equalsToken("TIMESTAMP", name) || equalsToken("TS", name)) { String timestamp = currentValue.getString();
@Override public Object getObject() { return getTime(); }
@Override public String getString() { StringBuilder buff = new StringBuilder(DISPLAY_SIZE); appendTime(buff, nanos, false); return buff.toString(); }
@Override public String getSQL() { return "TIME '" + getString() + "'"; }
/** * Get or create a time value. * * @param nanos the nanoseconds * @return the value */ public static ValueTime fromNanos(long nanos) { return (ValueTime) Value.cache(new ValueTime(nanos)); }
@Override public void writeValue(DataBuffer buff, Value v) { ValueTime t = (ValueTime) v; long nanos = t.getNanos(); long millis = nanos / 1000000; nanos -= millis * 1000000; buff.put((byte) TIME).putVarLong(millis).putVarLong(nanos); }
@Override public void set(PreparedStatement prep, int parameterIndex) throws SQLException { prep.setTime(parameterIndex, getTime()); }
@Override public String getString() { StringBuilder buff = new StringBuilder(DISPLAY_SIZE); ValueDate.appendDate(buff, dateValue); buff.append(' '); ValueTime.appendTime(buff, nanos, true); return buff.toString(); }
/** * Get or create a time value for the given time. * * @param time the time * @return the value */ public static ValueTime get(Time time) { return fromNanos(DateTimeUtils.nanosFromDate(time.getTime())); }
/** * Updates a column in the current or insert row. * * @param columnIndex (1,2,...) * @param x the value * @throws SQLException if the result set is closed or not updatable */ @Override public void updateTime(int columnIndex, Time x) throws SQLException { try { if (isDebugEnabled()) { debugCode("updateTime(" + columnIndex + ", x);"); } update(columnIndex, x == null ? (Value) ValueNull.INSTANCE : ValueTime.get(x)); } catch (Exception e) { throw logAndConvert(e); } }
break; case Value.TIME: writeLong(((ValueTime) v).getNanos()); break; case Value.TIMESTAMP: {
public Time getTime() { return ((ValueTime) convertTo(Value.TIME)).getTime(); }
@Override public Value multiply(Value v) { return ValueTime.fromNanos((long) (nanos * v.getDouble())); }
/** * Updates a column in the current or insert row. * * @param columnLabel the column label * @param x the value * @throws SQLException if the result set is closed or not updatable */ @Override public void updateTime(String columnLabel, Time x) throws SQLException { try { if (isDebugEnabled()) { debugCode("updateTime(" + quote(columnLabel) + ", x);"); } update(columnLabel, x == null ? (Value) ValueNull.INSTANCE : ValueTime.get(x)); } catch (Exception e) { throw logAndConvert(e); } }