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;
}
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));
}
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);
}
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());
}
Aggregations