From 9817bb2b4712e20e88f8a7803dec41d66263eb81 Mon Sep 17 00:00:00 2001 From: James Moger Date: Thu, 6 Nov 2014 19:39:11 -0500 Subject: [PATCH] Improve Date type conversions --- src/main/java/com/iciql/util/Utils.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/com/iciql/util/Utils.java b/src/main/java/com/iciql/util/Utils.java index e542054..346c6d7 100644 --- a/src/main/java/com/iciql/util/Utils.java +++ b/src/main/java/com/iciql/util/Utils.java @@ -31,6 +31,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.IdentityHashMap; @@ -320,6 +321,19 @@ public class Utils { } } + if (Date.class.isAssignableFrom(currentType)) { + Date d = (Date) o; + if (targetType == Date.class) { + return o; + } else if (targetType == java.sql.Date.class) { + return new java.sql.Date(d.getTime()); + } else if (targetType == java.sql.Time.class) { + return new java.sql.Time(d.getTime()); + } else if (targetType == java.sql.Timestamp.class) { + return new java.sql.Timestamp(d.getTime()); + } + } + // convert from BLOB if (targetType == byte[].class) { if (Blob.class.isAssignableFrom(currentType)) { -- 2.39.5