commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adri...@apache.org
Subject svn commit: r922474 - /commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/DateTimeConverters.java
Date Sat, 13 Mar 2010 03:24:20 GMT
Author: adrianc
Date: Sat Mar 13 03:24:20 2010
New Revision: 922474

URL: http://svn.apache.org/viewvc?rev=922474&view=rev
Log:
Fixed the non-localized String to java.sql.* conversions.

Modified:
    commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/DateTimeConverters.java

Modified: commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/DateTimeConverters.java
URL: http://svn.apache.org/viewvc/commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/DateTimeConverters.java?rev=922474&r1=922473&r2=922474&view=diff
==============================================================================
--- commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/DateTimeConverters.java
(original)
+++ commons/sandbox/convert/trunk/src/java/org/apache/commons/convert/DateTimeConverters.java
Sat Mar 13 03:24:20 2010
@@ -30,6 +30,21 @@ import java.util.TimeZone;
 /** Date/time Converter classes. */
 public class DateTimeConverters implements ConverterLoader {
     /**
+     * JDBC escape format for java.sql.Date conversions.
+     */
+    public static final String DATE_FORMAT = "yyyy-MM-dd";
+
+    /**
+     * JDBC escape format for java.sql.Timestamp conversions.
+     */
+    public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
+
+    /**
+     * JDBC escape format for java.sql.Time conversions.
+     */
+    public static final String TIME_FORMAT = "HH:mm:ss";
+
+    /**
      * Returns an initialized DateFormat object.
      *
      * @param dateFormat
@@ -369,6 +384,16 @@ public class DateTimeConverters implemen
             super(String.class, java.sql.Date.class);
         }
 
+        @Override
+        public java.sql.Date convert(String obj) throws ConversionException {
+            DateFormat df = new SimpleDateFormat(DATE_FORMAT);
+            try {
+                return new java.sql.Date(df.parse(obj).getTime());
+            } catch (ParseException e) {
+                throw new ConversionException(e);
+            }
+        }
+
         public java.sql.Date convert(String obj, Locale locale, TimeZone timeZone, String
formatString) throws ConversionException {
             DateFormat df = toDateFormat(formatString, timeZone, locale);
             try {
@@ -384,6 +409,16 @@ public class DateTimeConverters implemen
             super(String.class, java.sql.Time.class);
         }
 
+        @Override
+        public java.sql.Time convert(String obj) throws ConversionException {
+            DateFormat df = new SimpleDateFormat(TIME_FORMAT);
+            try {
+                return new java.sql.Time(df.parse(obj).getTime());
+            } catch (ParseException e) {
+                throw new ConversionException(e);
+            }
+        }
+
         public java.sql.Time convert(String obj, Locale locale, TimeZone timeZone, String
formatString) throws ConversionException {
             DateFormat df = toTimeFormat(formatString, timeZone, locale);
             try {
@@ -399,6 +434,16 @@ public class DateTimeConverters implemen
             super(String.class, java.sql.Timestamp.class);
         }
 
+        @Override
+        public Timestamp convert(String obj) throws ConversionException {
+            DateFormat df = new SimpleDateFormat(DATE_TIME_FORMAT);
+            try {
+                return new java.sql.Timestamp(df.parse(obj).getTime());
+            } catch (ParseException e) {
+                throw new ConversionException(e);
+            }
+        }
+
         public java.sql.Timestamp convert(String obj, Locale locale, TimeZone timeZone, String
formatString) throws ConversionException {
             DateFormat df = toDateTimeFormat(formatString, timeZone, locale);
             try {



Mime
View raw message