format((getMonth() + 1), 2, sb); sb.append('-'); format(getDate(), 2, sb); sb.append(' '); format(getHours(), 2, sb);
return LocalDateTime.of(timestamp.getYear() + 1900, timestamp.getMonth() + 1, timestamp.getDate(), timestamp.getHours(), timestamp.getMinutes(),
@SuppressWarnings("deprecation") private Timestamp withTZ(Timestamp timestamp, Calendar cal) { if (timestamp == null) return null; int year = timestamp.getYear() + 1900; int month = timestamp.getMonth(); int day = timestamp.getDate(); int hour = timestamp.getHours(); int minute = timestamp.getMinutes(); int second = timestamp.getSeconds(); int nanos = timestamp.getNanos(); int millis = nanos / 1000000; nanos = nanos - millis * 1000000; Timestamp r = new Timestamp(getMillis(cal, year, month, day, hour, minute, second, millis)); r.setNanos(nanos + millis * 1000000); return r; }
/** * Converts a {@code java.sql.Timestamp} to a {@code LocalDateTime}. * * @param sqlTimestamp the SQL timestamp, not null * @return the local date-time, not null */ @SuppressWarnings("deprecation") public static LocalDateTime toLocalDateTime(Timestamp sqlTimestamp) { return LocalDateTime.of( sqlTimestamp.getYear() + 1900, sqlTimestamp.getMonth() + 1, sqlTimestamp.getDate(), sqlTimestamp.getHours(), sqlTimestamp.getMinutes(), sqlTimestamp.getSeconds(), sqlTimestamp.getNanos()); }
format((getMonth() + 1), 2, sb); sb.append('-'); format(getDate(), 2, sb); sb.append(' '); format(getHours(), 2, sb);
format((getMonth() + 1), 2, sb); sb.append('-'); format(getDate(), 2, sb); sb.append(' '); format(getHours(), 2, sb);
format((getMonth() + 1), 2, sb); sb.append('-'); format(getDate(), 2, sb); sb.append(' '); format(getHours(), 2, sb);
@Override public JsonNode encodeToJson() { String text = String.format(ENGLISH, ISO_USEC_FORMAT, dateTime.getYear() + 1900, dateTime.getMonth() + 1, dateTime.getDate(), dateTime.getHours(), dateTime.getMinutes(), dateTime.getSeconds(), dateTime.getNanos() / 1000); return jsonNodeFactory.textNode(text); }
format((getMonth() + 1), 2, sb); sb.append('-'); format(getDate(), 2, sb); sb.append(' '); format(getHours(), 2, sb);
format((getMonth() + 1), 2, sb); sb.append('-'); format(getDate(), 2, sb); sb.append(' '); format(getHours(), 2, sb);
current.setDate((current.getDate()+days));
/** * Converts a {@code java.sql.Timestamp} to a {@code LocalDateTime}. * * @param sqlTimestamp the SQL timestamp, not null * @return the local date-time, not null */ @SuppressWarnings("deprecation") public static LocalDateTime toLocalDateTime(Timestamp sqlTimestamp) { return LocalDateTime.of( sqlTimestamp.getYear() + 1900, sqlTimestamp.getMonth() + 1, sqlTimestamp.getDate(), sqlTimestamp.getHours(), sqlTimestamp.getMinutes(), sqlTimestamp.getSeconds(), sqlTimestamp.getNanos()); }
/** * Converts a {@code java.sql.Timestamp} to a {@code LocalDateTime}. * * @param sqlTimestamp the SQL timestamp, not null * @return the local date-time, not null */ @SuppressWarnings("deprecation") public static LocalDateTime toLocalDateTime(Timestamp sqlTimestamp) { return LocalDateTime.of( sqlTimestamp.getYear() + 1900, sqlTimestamp.getMonth() + 1, sqlTimestamp.getDate(), sqlTimestamp.getHours(), sqlTimestamp.getMinutes(), sqlTimestamp.getSeconds(), sqlTimestamp.getNanos()); }
@SuppressWarnings("deprecation") public static long toDate(Heap heap, long pValue) { if (pValue == 0) { return 0; } int type = Value.getType(heap, pValue); Date result; if (type == Value.TYPE_DATE) { return pValue; } else if (type == Value.TYPE_TIMESTAMP) { Timestamp value = FishTimestamp.get(heap, pValue); result = new Date(value.getYear(), value.getMonth(), value.getDate()); } else if (type == Value.TYPE_STRING) { String text = (String)FishObject.get(heap, pValue); result = parseDate(text); if (result == null) { throw new OrcaException("invalid date value: " + text); } } else if (type == Value.TYPE_BYTES) { pValue = toString(heap, pValue); return toDate(heap, pValue); } else { throw new IllegalArgumentException(); } return FishObject.allocSet(heap, result); }
@Test public void testSymmetricTimestampCoercion() { Object canonical = sqlTimestampCoercibleType.canonical( inputTimestamp ); Timestamp coerced = (Timestamp) sqlTimestampCoercibleType.coerce( canonical, java.sql.Timestamp.class ); // multiple coercions should preserve date. Run it 24 times to catch any timezone issue. for( int i = 0; i < 24; i++ ) { canonical = sqlTimestampCoercibleType.canonical( coerced ); assertEquals( "Canonical value changed on iteration " + i, timeAsLong, ( (Long) canonical ).longValue() ); coerced = (Timestamp) sqlTimestampCoercibleType.coerce( canonical, java.sql.Timestamp.class ); assertEquals( "Coerced day changed on iteration " + i + " now: " + coerced.toString(), inputTimestamp.getDate(), coerced.getDate() ); assertEquals( "Coerced month changed on iteration " + i + " now: " + coerced.toString(), inputTimestamp.getMonth(), coerced.getMonth() ); assertEquals( "Coerced year changed on iteration " + i + " now: " + coerced.toString(), inputTimestamp.getYear(), coerced.getYear() ); assertEquals( "Coerced hour changed on iteration " + i + " now: " + coerced.toString(), inputTimestamp.getHours(), coerced.getHours() ); } }
@Test public void testTimestampFromStringCoercion() { // as run in tests we go from UTC to local time by coercing. String dateAsString = "1996-08-04 01:02:03"; Long canonical = (Long) sqlTimestampCoercibleType.canonical( dateAsString ); Timestamp coerced = (Timestamp) sqlTimestampCoercibleType.coerce( canonical, java.sql.Timestamp.class ); assertEquals( "String parsing got wrong day", 4, coerced.getDate() ); assertEquals( "String parsing got wrong month", 7, coerced.getMonth() ); assertEquals( "String parsing got wrong year", 96, coerced.getYear() ); assertEquals( "String parsing got wrong hour", 1, coerced.getHours() ); assertEquals( "String parsing got wrong minute", 2, coerced.getMinutes()); assertEquals( "String parsing got wrong second", 3, coerced.getSeconds() ); }