Search in sources :

Example 1 with InstantKvInstant

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());
}
Also used : InstantKvInstant(com.torodb.kvdocument.values.heap.InstantKvInstant) Test(org.junit.Test)

Example 2 with InstantKvInstant

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);
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) LongKvInstant(com.torodb.kvdocument.values.heap.LongKvInstant) TemporalAccessor(java.time.temporal.TemporalAccessor) KvLong(com.torodb.kvdocument.values.KvLong) StringKvString(com.torodb.kvdocument.values.heap.StringKvString) DateTimeFormatter(java.time.format.DateTimeFormatter) KvDouble(com.torodb.kvdocument.values.KvDouble) InstantKvInstant(com.torodb.kvdocument.values.heap.InstantKvInstant)

Aggregations

InstantKvInstant (com.torodb.kvdocument.values.heap.InstantKvInstant)2 KvDouble (com.torodb.kvdocument.values.KvDouble)1 KvLong (com.torodb.kvdocument.values.KvLong)1 LongKvInstant (com.torodb.kvdocument.values.heap.LongKvInstant)1 StringKvString (com.torodb.kvdocument.values.heap.StringKvString)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 DateTimeParseException (java.time.format.DateTimeParseException)1 TemporalAccessor (java.time.temporal.TemporalAccessor)1 Test (org.junit.Test)1