Search in sources :

Example 1 with KvInstant

use of com.torodb.kvdocument.values.KvInstant in project torodb by torodb.

the class InstantValueConverter method to.

@Override
public Timestamp to(KvInstant userObject) {
    Instant instant = userObject.getValue();
    try {
        Timestamp ts = new Timestamp(instant.getEpochSecond() * 1000);
        ts.setNanos(instant.getNano());
        return ts;
    } catch (ArithmeticException ex) {
        throw new IllegalArgumentException(ex);
    }
}
Also used : InstantKvInstant(com.torodb.kvdocument.values.heap.InstantKvInstant) KvInstant(com.torodb.kvdocument.values.KvInstant) Instant(java.time.Instant) Timestamp(java.sql.Timestamp)

Example 2 with KvInstant

use of com.torodb.kvdocument.values.KvInstant in project torodb by torodb.

the class InstantValueConverter method to.

@Override
public Timestamp to(KvInstant userObject) {
    Instant instant = userObject.getValue();
    try {
        Timestamp ts = new Timestamp(instant.getEpochSecond() * 1000);
        ts.setNanos(instant.getNano());
        return ts;
    } catch (ArithmeticException ex) {
        throw new IllegalArgumentException(ex);
    }
}
Also used : InstantKvInstant(com.torodb.kvdocument.values.heap.InstantKvInstant) KvInstant(com.torodb.kvdocument.values.KvInstant) Instant(java.time.Instant) Timestamp(java.sql.Timestamp)

Example 3 with KvInstant

use of com.torodb.kvdocument.values.KvInstant in project torodb by torodb.

the class TestConvertJson method parseDate.

@Test
public void parseDate() {
    KvDocument doc = parser.createFromResource("DateField.json");
    assertTrue(doc.containsKey("creation"));
    KvValue<?> creation = doc.get("creation");
    assertTrue(creation instanceof KvInstant);
}
Also used : KvDocument(com.torodb.kvdocument.values.KvDocument) KvInstant(com.torodb.kvdocument.values.KvInstant) Test(org.junit.Test)

Aggregations

KvInstant (com.torodb.kvdocument.values.KvInstant)3 InstantKvInstant (com.torodb.kvdocument.values.heap.InstantKvInstant)2 Timestamp (java.sql.Timestamp)2 Instant (java.time.Instant)2 KvDocument (com.torodb.kvdocument.values.KvDocument)1 Test (org.junit.Test)1