StringBuilder sb = new StringBuilder(29); format((getYear() + 1900), 4, sb); sb.append('-'); format((getMonth() + 1), 2, sb);
return LocalDateTime.of(timestamp.getYear() + 1900, timestamp.getMonth() + 1, timestamp.getDate(),
assertEquals(FooWeight.light, foo.weight); assertNotNull(foo.timestamp); assertEquals(109, foo.timestamp.getYear()); assertEquals(6, foo.timestamp.getHours()); assertEquals(5, foo.timestamp.getMinutes()); assertEquals(FooColor.yellow, foo.color); assertEquals(FooWeight.heavy, foo.weight); assertEquals(108, foo.timestamp.getYear()); assertEquals(2010, foo.timestamp2.getYear()); assertEquals(20, foo.timestamp2.getHour());
@Test public void testCurrentTimeWithProjectedTable () throws Exception { String tableName1 = generateUniqueName(); String tableName2 = generateUniqueName(); String ddl = "CREATE TABLE " + tableName1 + " ( ID integer primary key)"; conn.createStatement().execute(ddl); ddl = "CREATE TABLE " + tableName2 + " ( ID integer primary key)"; conn.createStatement().execute(ddl); String ups = "UPSERT INTO " + tableName1 + " VALUES (1)"; conn.createStatement().execute(ups); ups = "UPSERT INTO " + tableName2 + " VALUES (1)"; conn.createStatement().execute(ups); conn.commit(); ResultSet rs = conn.createStatement().executeQuery("select /*+ USE_SORT_MERGE_JOIN */ op" + ".id, current_time() from " +tableName1 + " op where op.id in (select id from " + tableName2 + ")"); assertTrue(rs.next()); assertEquals(new java.util.Date().getYear(),rs.getTimestamp(2).getYear()); }
@SuppressWarnings("deprecation") @Override public long eval(VdmContext ctx, Heap heap, Parameters params, long pRecord) { long pValue = this.parameters.get(0).eval(ctx, heap, params, pRecord); if (pValue == 0) { return 0; } pValue = AutoCaster.toTimestamp(heap, pValue); Timestamp ts = FishTimestamp.get(heap, pValue); return Int4.allocSet(heap, ts.getYear() + 1900); }
StringBuilder sb = new StringBuilder(29); format((getYear() + 1900), 4, sb); sb.append('-'); format((getMonth() + 1), 2, sb);
@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()); }
StringBuilder sb = new StringBuilder(29); format((getYear() + 1900), 4, sb); sb.append('-'); format((getMonth() + 1), 2, sb);
StringBuilder sb = new StringBuilder(29); format((getYear() + 1900), 4, sb); sb.append('-'); format((getMonth() + 1), 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); }
/** * 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()); }
@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() ); }