Search in sources :

Example 1 with ISO8601DateSerde

use of com.yahoo.elide.core.utils.coerce.converters.ISO8601DateSerde in project elide by yahoo.

the class ElideSettingsBuilder method withISO8601Dates.

public ElideSettingsBuilder withISO8601Dates(String dateFormat, TimeZone tz) {
    serdes.put(Date.class, new ISO8601DateSerde(dateFormat, tz));
    serdes.put(java.sql.Date.class, new ISO8601DateSerde(dateFormat, tz, java.sql.Date.class));
    serdes.put(java.sql.Time.class, new ISO8601DateSerde(dateFormat, tz, java.sql.Time.class));
    serdes.put(java.sql.Timestamp.class, new ISO8601DateSerde(dateFormat, tz, java.sql.Timestamp.class));
    return this;
}
Also used : ISO8601DateSerde(com.yahoo.elide.core.utils.coerce.converters.ISO8601DateSerde) OffsetDateTime(java.time.OffsetDateTime) Date(java.util.Date)

Example 2 with ISO8601DateSerde

use of com.yahoo.elide.core.utils.coerce.converters.ISO8601DateSerde in project elide by yahoo.

the class EntityDictionaryTest method testSerdeId.

@Test
public void testSerdeId() {
    @Include(rootLevel = false)
    class EntityWithDateId {

        @Id
        private Date id;
    }
    EntityDictionary testDictionary = new EntityDictionary(new HashMap<>(), null, DEFAULT_INJECTOR, unused -> new ISO8601DateSerde(), Collections.emptySet(), DefaultClassScanner.getInstance());
    testDictionary.bindEntity(EntityWithDateId.class);
    EntityWithDateId testModel = new EntityWithDateId();
    testModel.id = new Date(0);
    assertEquals("1970-01-01T00:00Z", testDictionary.getId(testModel));
}
Also used : ISO8601DateSerde(com.yahoo.elide.core.utils.coerce.converters.ISO8601DateSerde) Include(com.yahoo.elide.annotation.Include) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 3 with ISO8601DateSerde

use of com.yahoo.elide.core.utils.coerce.converters.ISO8601DateSerde in project elide by yahoo.

the class CoerceUtilTest method testDateToTimestamp.

@Test
public void testDateToTimestamp() {
    String dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'";
    TimeZone tz = TimeZone.getTimeZone("UTC");
    Serde oldDateSerde = CoerceUtil.lookup(Date.class);
    Serde oldTimestampSerde = CoerceUtil.lookup(java.sql.Timestamp.class);
    Serde timestampSerde = new ISO8601DateSerde(dateFormat, tz, java.sql.Timestamp.class);
    CoerceUtil.register(Date.class, new ISO8601DateSerde(dateFormat, tz));
    CoerceUtil.register(java.sql.Timestamp.class, timestampSerde);
    Date date = new Date();
    Timestamp timestamp = CoerceUtil.coerce(date, Timestamp.class);
    assertEquals(date.getTime(), timestamp.getTime());
    CoerceUtil.register(Date.class, oldDateSerde);
    CoerceUtil.register(java.sql.Timestamp.class, oldTimestampSerde);
}
Also used : ISO8601DateSerde(com.yahoo.elide.core.utils.coerce.converters.ISO8601DateSerde) Serde(com.yahoo.elide.core.utils.coerce.converters.Serde) TimeZone(java.util.TimeZone) ISO8601DateSerde(com.yahoo.elide.core.utils.coerce.converters.ISO8601DateSerde) Timestamp(java.sql.Timestamp) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 4 with ISO8601DateSerde

use of com.yahoo.elide.core.utils.coerce.converters.ISO8601DateSerde in project elide by yahoo.

the class GraphQLScalarsTest method init.

@BeforeAll
public void init() {
    oldSerde = CoerceUtil.lookup(Date.class);
    CoerceUtil.register(Date.class, new ISO8601DateSerde("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC"), java.sql.Date.class));
    CoerceUtil.register(OffsetDateTime.class, new OffsetDateTimeSerde());
}
Also used : OffsetDateTimeSerde(com.yahoo.elide.core.utils.coerce.converters.OffsetDateTimeSerde) ISO8601DateSerde(com.yahoo.elide.core.utils.coerce.converters.ISO8601DateSerde) Date(java.util.Date) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

ISO8601DateSerde (com.yahoo.elide.core.utils.coerce.converters.ISO8601DateSerde)4 Date (java.util.Date)4 Test (org.junit.jupiter.api.Test)2 Include (com.yahoo.elide.annotation.Include)1 OffsetDateTimeSerde (com.yahoo.elide.core.utils.coerce.converters.OffsetDateTimeSerde)1 Serde (com.yahoo.elide.core.utils.coerce.converters.Serde)1 Timestamp (java.sql.Timestamp)1 OffsetDateTime (java.time.OffsetDateTime)1 TimeZone (java.util.TimeZone)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1