/** * Get or create a date value for the given date. * * @param date the date * @return the value */ public static ValueDate get(Date date) { return fromDateValue(DateTimeUtils.dateValueFromDate(date.getTime())); }
@Override public void writeValue(DataBuffer buff, Value v) { long d = ((ValueDate) v).getDateValue(); write0(buff, d); }
/** * Get or create a date value for the given date. * * @param dateValue the date value * @return the value */ public static ValueDate fromDateValue(long dateValue) { return (ValueDate) Value.cache(new ValueDate(dateValue)); }
/** * 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 updateDate(int columnIndex, Date x) throws SQLException { try { if (isDebugEnabled()) { debugCode("updateDate(" + columnIndex + ", x);"); } update(columnIndex, x == null ? (Value) ValueNull.INSTANCE : ValueDate.get(x)); } catch (Exception e) { throw logAndConvert(e); } }
return ValueDate.fromDateValue(DateTimeUtils.dateValue(1970, 1, 1)); case TIMESTAMP: return ValueDate.fromDateValue(((ValueTimestamp) this).getDateValue()); return DateTimeUtils.normalizeTimestamp(0, ((ValueTime) this).getNanos()); case DATE: return ValueTimestamp.fromDateValueAndNanos(((ValueDate) this).getDateValue(), 0); return ValueTime.parse(s.trim()); case DATE: return ValueDate.parse(s.trim()); case TIMESTAMP: return ValueTimestamp.parse(s.trim());
String date = currentValue.getString(); read(); r = ValueExpression.get(ValueDate.parse(date)); } else if (equalsToken("TIME", name) || equalsToken("T", name)) { String time = currentValue.getString();
@Override public Object getObject() { return getDate(); }
@Override public String getString() { StringBuilder buff = new StringBuilder(DISPLAY_SIZE); appendDate(buff, dateValue); return buff.toString(); }
/** * 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 updateDate(String columnLabel, Date x) throws SQLException { try { if (isDebugEnabled()) { debugCode("updateDate(" + quote(columnLabel) + ", x);"); } update(columnLabel, x == null ? (Value) ValueNull.INSTANCE : ValueDate.get(x)); } catch (Exception e) { throw logAndConvert(e); } }
@Override public void set(PreparedStatement prep, int parameterIndex) throws SQLException { prep.setDate(parameterIndex, getDate()); }
@Override public String getString() { StringBuilder buff = new StringBuilder(DISPLAY_SIZE); ValueDate.appendDate(buff, dateValue); buff.append(' '); ValueTime.appendTime(buff, nanos, true); return buff.toString(); }
/** * Sets the value of a parameter. * * @param parameterIndex the parameter index (1, 2, ...) * @param x the value * @throws SQLException if this object is closed */ @Override public void setDate(int parameterIndex, java.sql.Date x) throws SQLException { try { if (isDebugEnabled()) { debugCode("setDate(" + parameterIndex + ", " + quoteDate(x) + ");"); } Value v = x == null ? (Value) ValueNull.INSTANCE : ValueDate.get(x); setParameter(parameterIndex, v); } catch (Exception e) { throw logAndConvert(e); } }
@Override public Value readValue(ByteBuffer buff) { return ValueDate.fromDateValue(DataUtils.readVarLong(buff)); }
/** * Convert the date to the specified time zone. * * @param value the date (might be ValueNull) * @param calendar the calendar * @return the date using the correct time zone */ public static Date convertDate(Value value, Calendar calendar) { if (value == ValueNull.INSTANCE) { return null; } ValueDate d = (ValueDate) value.convertTo(Value.DATE); Calendar cal = (Calendar) calendar.clone(); cal.clear(); cal.setLenient(true); long dateValue = d.getDateValue(); setCalendarFields(cal, yearFromDateValue(dateValue), monthFromDateValue(dateValue), dayFromDateValue(dateValue), 0, 0, 0, 0); long ms = cal.getTimeInMillis(); return new Date(ms); }
public Date getDate() { return ((ValueDate) convertTo(Value.DATE)).getDate(); }
v = value == null ? (Value) ValueNull.INSTANCE : ValueDate.get(value); break;
/** * Convert the date using the specified calendar. * * @param x the date * @param calendar the calendar * @return the date */ public static ValueDate convertDate(Date x, Calendar calendar) { if (calendar == null) { throw DbException.getInvalidValueException("calendar", null); } Calendar cal = (Calendar) calendar.clone(); cal.setTimeInMillis(x.getTime()); long dateValue = dateValueFromCalendar(cal); return ValueDate.fromDateValue(dateValue); }
break; case Value.DATE: writeLong(((ValueDate) v).getDateValue()); break; case Value.TIME:
return ValueBytes.get((byte[]) x); } else if (x instanceof Date) { return ValueDate.get((Date) x); } else if (x instanceof Time) { return ValueTime.get((Time) x);
/** * Parse a string to a ValueDate. * * @param s the string to parse * @return the date */ public static ValueDate parse(String s) { try { return fromDateValue(DateTimeUtils.parseDateValue(s, 0, s.length())); } catch (Exception e) { throw DbException.get(ErrorCode.INVALID_DATETIME_CONSTANT_2, e, "DATE", s); } }