ofbiz-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doo...@apache.org
Subject svn commit: r917367 - in /ofbiz/trunk/framework/base/src/org/ofbiz/base: conversion/DateTimeConverters.java util/test/ObjectTypeTests.java
Date Mon, 01 Mar 2010 03:14:59 GMT
Author: doogie
Date: Mon Mar  1 03:14:59 2010
New Revision: 917367

URL: http://svn.apache.org/viewvc?rev=917367&view=rev
Log:
BUG FIX: in StringToDuration converter, handle the case where there is
no : in the string, and it's just a plain number.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/ObjectTypeTests.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java?rev=917367&r1=917366&r2=917367&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java Mon Mar
 1 03:14:59 2010
@@ -19,6 +19,7 @@
 package org.ofbiz.base.conversion;
 
 import java.text.DateFormat;
+import java.text.NumberFormat;
 import java.text.ParseException;
 import java.util.Date;
 import java.util.List;
@@ -409,13 +410,32 @@
         }
     }
 
-    public static class StringToDuration extends AbstractConverter<String, TimeDuration>
{
+    public static class StringToDuration extends AbstractLocalizedConverter<String, TimeDuration>
{
         public StringToDuration() {
             super(String.class, TimeDuration.class);
         }
 
+        public TimeDuration convert(String obj, Locale locale, TimeZone timeZone, String
formatString) throws ConversionException {
+            return convert(obj, locale, timeZone);
+        }
+
+        public TimeDuration convert(String obj, Locale locale, TimeZone timeZone) throws
ConversionException {
+            if (!obj.contains(":")) {
+                // Encoded duration
+                try {
+                    NumberFormat nf = NumberFormat.getNumberInstance(locale);
+                    nf.setMaximumFractionDigits(0);
+                    Number number = nf.parse(obj);
+                    return TimeDuration.fromNumber(number);
+                } catch (ParseException e) {
+                    throw new ConversionException(e);
+                }
+            }
+            return convert(obj);
+        }
+
         public TimeDuration convert(String obj) throws ConversionException {
-             return TimeDuration.parseDuration(obj);
+            return TimeDuration.parseDuration(obj);
         }
     }
 

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/ObjectTypeTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/ObjectTypeTests.java?rev=917367&r1=917366&r2=917367&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/ObjectTypeTests.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/test/ObjectTypeTests.java Mon Mar 
1 03:14:59 2010
@@ -240,7 +240,7 @@
         simpleTypeConvertTestSingleMulti("String->Map", "{one=1, two=2, three=3}", new
String[] {"Map", "java.util.Map"}, map);
         simpleTypeConvertTestError("String->Map(error-1)", "{one=1, two=2, three=3", new
String[] {"Map", "java.util.Map"});
         simpleTypeConvertTestError("String->Map(error-2)", "one=1, two=2, three=3}", new
String[] {"Map", "java.util.Map"});
-        //BUG simpleTypeConvertTestSingleMulti("String->TimeDuration(number)", "3,661,001",
new String[] {"TimeDuration", "org.ofbiz.base.util.TimeDuration"}, null, localeData, duration);
+        simpleTypeConvertTestSingleMulti("String->TimeDuration(number)", "3,661,001",
new String[] {"TimeDuration", "org.ofbiz.base.util.TimeDuration"}, null, localeData, duration);
         simpleTypeConvertTestMultiMulti("String->TimeDuration(string)", new String[] {"1:1:1:1"},
new String[] {"TimeDuration", "org.ofbiz.base.util.TimeDuration"}, duration);
         //BUG simpleTypeConvertTestError("String->error-TimeDuration", "o", new String[]
{"TimeDuration", "org.ofbiz.base.util.TimeDuration"});
     }



Mime
View raw message