use of com.torodb.kvdocument.values.heap.InstantKvInstant in project torodb by torodb.
the class PostgreSqlValueToCopyConverterTest method testDateTimeValue.
@Test
public void testDateTimeValue() {
new InstantKvInstant(LocalDateTime.of(2015, Month.JANUARY, 18, 2, 43, 26).toInstant(ZoneOffset.UTC)).accept(visitor, sb);
assertEquals("'2015-01-18T02:43:26Z'", sb.toString());
}
use of com.torodb.kvdocument.values.heap.InstantKvInstant in project torodb by torodb.
the class MapToKvValueConverter method parseDate.
private KvInstant parseDate(String key, Object value) {
if ("$date".equals(key) && value instanceof String) {
try {
DateTimeFormatter sdf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX");
TemporalAccessor date = sdf.parse((String) value);
return new InstantKvInstant(Instant.from(date));
} catch (DateTimeParseException e) {
throw new RuntimeException("Unexpected error parsing date", e);
}
}
if ("$date".equals(key) && value instanceof Long) {
return new LongKvInstant((Long) value);
}
if ("$date".equals(key) && value instanceof Double) {
return new LongKvInstant(((Double) value).longValue());
}
throw new RuntimeException("Unexpected date object type: " + key);
}
Aggregations