@Override public LocalDate convert(LocalDateTime source) { return source.toLocalDate(); } }
@Override public LocalDate convert(LocalDateTime source) { return source.toLocalDate(); } }
@Override LocalDate getDatePart() { return value.toLocalDate(); }
public void setTimeInMillis(long epochMilli) { localDate = LocalDateTime.ofInstant( Instant.ofEpochMilli(epochMilli), ZoneOffset.UTC).toLocalDate(); }
@Override @Nullable public LocalDate mapColumn(ResultSet r, int columnNumber, StatementContext ctx) throws SQLException { final Timestamp timestamp = r.getTimestamp(columnNumber); if (timestamp == null) { return null; } return timestamp.toLocalDateTime().toLocalDate(); } }
@Override @Nullable public LocalDate mapColumn(ResultSet r, String columnLabel, StatementContext ctx) throws SQLException { final Timestamp timestamp = r.getTimestamp(columnLabel); if (timestamp == null) { return null; } return timestamp.toLocalDateTime().toLocalDate(); }
@Override public TemporalAccessor cast(Number src, Class<?> toType, String... args) { Date date = new Date(src.longValue()); LocalDateTime dt = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); if (toType == LocalDateTime.class) return dt; if (toType == LocalDate.class) return dt.toLocalDate(); return dt.toLocalTime(); }
public static Date ofEpochMilli(long epochMilli) { return new Date(LocalDateTime.ofInstant( Instant.ofEpochMilli(epochMilli), ZoneOffset.UTC).toLocalDate()); }
@Override public LocalDate readLocalDate(){ if (!isSet()) { return null; } return LocalDateTime.ofInstant(Instant.ofEpochMilli(this.holder.value), ZoneOffset.UTC).toLocalDate(); }
public static Date castToDate(Object x, int targetSqlType) throws SQLException { if (x instanceof Date) { return (Date) x; } if (x instanceof java.util.Date) { return new Date(((java.util.Date) x).getTime()); } if (x instanceof LocalDate) { return Date.valueOf((LocalDate) x); } if (x instanceof LocalDateTime) { return Date.valueOf(((LocalDateTime) x).toLocalDate()); } try { if (x instanceof String) { return Date.valueOf((String) x); } } catch (RuntimeException e) { throw invalidConversion(x, targetSqlType, e); } throw invalidConversion(x, targetSqlType); }
/** * Compute the expired date partition, using the underlying clock in UTC time. */ private static void computeExpiredDatePtn(long ttl) { // Use UTC date to ensure reader date is same on all timezones. LocalDate expiredDate = LocalDateTime.ofEpochSecond((clock.getTime() - ttl) / 1000, 0, ZoneOffset.UTC).toLocalDate(); expiredDatePtn = "date=" + DateTimeFormatter.ISO_LOCAL_DATE.format(expiredDate); }
/** * Constructs standard (non-legacy) TIMESTAMP value corresponding to argument */ public static SqlTimestamp sqlTimestampOf(LocalDateTime dateTime) { return new SqlTimestamp(DAYS.toMillis(dateTime.toLocalDate().toEpochDay()) + NANOSECONDS.toMillis(dateTime.toLocalTime().toNanoOfDay())); }
/** * Creates a writer for the given fileName, with date as today. */ public ProtoMessageWriter<T> getWriter(String fileName) throws IOException { Path filePath = getPathForDate(getNow().toLocalDate(), fileName); return new ProtoMessageWriter<>(conf, filePath, parser); }
/** * Get the number of nanoseconds past epoch of the given {@link LocalDateTime}. * * @param timestamp the Java timestamp value * @return the epoch nanoseconds */ static long toEpochNanos(LocalDateTime timestamp) { long nanoInDay = timestamp.toLocalTime().toNanoOfDay(); long nanosOfDay = toEpochNanos(timestamp.toLocalDate()); return nanosOfDay + nanoInDay; }
public static long pack(LocalDateTime dateTime) { if (dateTime == null) { return missingValueIndicator(); } LocalDate date = dateTime.toLocalDate(); LocalTime time = dateTime.toLocalTime(); return (pack(date, time)); }
@Test public void testConvertTimestamp() throws SQLException { LocalDateTime dateTime = LocalDateTime.of(2001, 5, 6, 12, 34, 56); Date sqlDate = Date.valueOf(dateTime.toLocalDate()); Time sqlTime = Time.valueOf(dateTime.toLocalTime()); Timestamp sqlTimestamp = Timestamp.valueOf(dateTime); java.util.Date javaDate = java.util.Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant()); assertParameter(sqlTimestamp, Types.TIMESTAMP, (ps, i) -> ps.setTimestamp(i, sqlTimestamp)); assertParameter(sqlTimestamp, Types.TIMESTAMP, (ps, i) -> ps.setObject(i, sqlTimestamp)); assertParameter(new Timestamp(sqlDate.getTime()), Types.TIMESTAMP, (ps, i) -> ps.setObject(i, sqlDate, Types.TIMESTAMP)); assertParameter(new Timestamp(sqlTime.getTime()), Types.TIMESTAMP, (ps, i) -> ps.setObject(i, sqlTime, Types.TIMESTAMP)); assertParameter(sqlTimestamp, Types.TIMESTAMP, (ps, i) -> ps.setObject(i, sqlTimestamp, Types.TIMESTAMP)); assertParameter(sqlTimestamp, Types.TIMESTAMP, (ps, i) -> ps.setObject(i, javaDate, Types.TIMESTAMP)); assertParameter(sqlTimestamp, Types.TIMESTAMP, (ps, i) -> ps.setObject(i, dateTime, Types.TIMESTAMP)); assertParameter(sqlTimestamp, Types.TIMESTAMP, (ps, i) -> ps.setObject(i, "2001-05-06 12:34:56", Types.TIMESTAMP)); }
@Override public void writeObject(ObjectOutput output, LocalDateTime dateTime) throws IOException { DefaultExternalizer.LOCAL_DATE.cast(LocalDate.class).writeObject(output, dateTime.toLocalDate()); DefaultExternalizer.LOCAL_TIME.cast(LocalTime.class).writeObject(output, dateTime.toLocalTime()); }
@Test public void shouldReturnLocalDateInstanceWhenConvertingLocalDateTimeToLocalDate() { LocalDateTime now = LocalDateTime.now(); assertThat(Conversions.toLocalDate(now)).isEqualTo(now.toLocalDate()); }
@Test public void testDate() { LocalDateTime dateTime = LocalDateTime.of(2018, 4, 10, 7, 30); startCol.append(dateTime); DateColumn date = startCol.date(); assertEquals(dateTime.toLocalDate(), date.get(0)); }
@Test public void testAsLocalDateTime() { LocalDateTime dateTime = LocalDateTime.now(); long packed = pack(dateTime.toLocalDate(), dateTime.toLocalTime()); LocalDateTime upacked = asLocalDateTime(packed); assertEquals(dateTime.getDayOfYear(), upacked.getDayOfYear()); assertEquals(dateTime.getHour(), upacked.getHour()); assertEquals(dateTime.getMinute(), upacked.getMinute()); assertEquals(dateTime.getSecond(), upacked.getSecond()); }