labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simo...@apache.org
Subject svn commit: r718576 - in /labs/magma/trunk/foundation-conversion/src: main/java/org/apache/magma/conversion/ test/java/org/apache/magma/conversion/
Date Tue, 18 Nov 2008 13:23:37 GMT
Author: simoneg
Date: Tue Nov 18 05:23:37 2008
New Revision: 718576

URL: http://svn.apache.org/viewvc?rev=718576&view=rev
Log:
Support ISO-RFC822 date formats

Modified:
    labs/magma/trunk/foundation-conversion/src/main/java/org/apache/magma/conversion/DateConverter.java
    labs/magma/trunk/foundation-conversion/src/test/java/org/apache/magma/conversion/TestDateConverterFromStringCorrect.java
    labs/magma/trunk/foundation-conversion/src/test/java/org/apache/magma/conversion/TestDateConverterToStringCorrect.java

Modified: labs/magma/trunk/foundation-conversion/src/main/java/org/apache/magma/conversion/DateConverter.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-conversion/src/main/java/org/apache/magma/conversion/DateConverter.java?rev=718576&r1=718575&r2=718576&view=diff
==============================================================================
--- labs/magma/trunk/foundation-conversion/src/main/java/org/apache/magma/conversion/DateConverter.java
(original)
+++ labs/magma/trunk/foundation-conversion/src/main/java/org/apache/magma/conversion/DateConverter.java
Tue Nov 18 05:23:37 2008
@@ -33,9 +33,10 @@
 		patterns.add("yyyy");
 		patterns.add("yyyy-MM");
 		patterns.add("yyyy-MM-dd");
-		patterns.add("yyyy-MM-dd HH:mm");
-		patterns.add("yyyy-MM-dd HH:mm:ss");
-		patterns.add("yyyy-MM-dd HH:mm:ss.SSS");
+		patterns.add("yyyy-MM-dd'T'HH:mm");
+		patterns.add("yyyy-MM-dd'T'HH:mm:ss");
+		patterns.add("yyyy-MM-dd'T'HH:mm:ss.SSS");
+		patterns.add("yyyy-MM-dd'T'HH:mm:ssz");
 	}
 	
 	protected LocalizableString parsingError = new LocalizableString("Invalid date");		
@@ -48,6 +49,16 @@
 		if (value == null || value.length() == 0) return null;
 		SimpleDateFormat sdf = null;
 		int len = value.length();
+		if (value.indexOf('T') != -1) len += 2;
+		int tzof = value.indexOf('+'); 
+		if (tzof != -1) {
+			int tps = value.indexOf(':', tzof);
+			if (tps != -1) {
+				value = value.substring(0,tps) + value.substring(tps + 1);
+				len --;
+			}
+			len -= 4;
+		}
 		for (String patt : patterns) {
 			if (patt.length() == len) {
 				sdf = new SimpleDateFormat(patt);
@@ -65,7 +76,7 @@
 
 	public String toString(Date value) {
 		if (value == null) return "";
-		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
 		StringBuilder ret = new StringBuilder(sdf.format(value));
 		if (ret.substring(ret.length() - 3, ret.length()).equals("000")) {
 			ret.delete(ret.length() - 4, ret.length());

Modified: labs/magma/trunk/foundation-conversion/src/test/java/org/apache/magma/conversion/TestDateConverterFromStringCorrect.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-conversion/src/test/java/org/apache/magma/conversion/TestDateConverterFromStringCorrect.java?rev=718576&r1=718575&r2=718576&view=diff
==============================================================================
--- labs/magma/trunk/foundation-conversion/src/test/java/org/apache/magma/conversion/TestDateConverterFromStringCorrect.java
(original)
+++ labs/magma/trunk/foundation-conversion/src/test/java/org/apache/magma/conversion/TestDateConverterFromStringCorrect.java
Tue Nov 18 05:23:37 2008
@@ -38,20 +38,21 @@
 	@Before
 	public void initConverter() {
 		converter = new DateConverter();
-		sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+		sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
 	}
 			
 	@DataPoint public static String[]
-	set1 = {"2008", "2008-01-01 00:00:00.000"},
-	set2 = {"2008-02", "2008-02-01 00:00:00.000"},
-	set3 = {"2008-02-02", "2008-02-02 00:00:00.000"},
-	set4 = {"2008-02-02 15:40", "2008-02-02 15:40:00.000"},
-	set5 = {"2008-02-02 15:40:10", "2008-02-02 15:40:10.000"},
-	set6 = {"2008-02-02 15:40:10.423", "2008-02-02 15:40:10.423"};
+	set1 = {"2008", "2008-01-01T00:00:00.000"},
+	set2 = {"2008-02", "2008-02-01T00:00:00.000"},
+	set3 = {"2008-02-02", "2008-02-02T00:00:00.000"},
+	set4 = {"2008-02-02T15:40", "2008-02-02T15:40:00.000"},
+	set5 = {"2008-02-02T15:40:10", "2008-02-02T15:40:10.000"},
+	set6 = {"2008-02-02T15:40:10.423", "2008-02-02T15:40:10.423"};
 	
 	@Theory public void convert(String[] vals) {
 		Date d = converter.fromString(vals[0]);
 		String ctrl = sdf.format(d);
+		//System.out.println(vals[1] + " -> " + vals[0] + " = " + ctrl);
 		assertEquals(ctrl, vals[1]);
 	}
 	

Modified: labs/magma/trunk/foundation-conversion/src/test/java/org/apache/magma/conversion/TestDateConverterToStringCorrect.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-conversion/src/test/java/org/apache/magma/conversion/TestDateConverterToStringCorrect.java?rev=718576&r1=718575&r2=718576&view=diff
==============================================================================
--- labs/magma/trunk/foundation-conversion/src/test/java/org/apache/magma/conversion/TestDateConverterToStringCorrect.java
(original)
+++ labs/magma/trunk/foundation-conversion/src/test/java/org/apache/magma/conversion/TestDateConverterToStringCorrect.java
Tue Nov 18 05:23:37 2008
@@ -39,16 +39,16 @@
 	@Before
 	public void initConverter() {
 		converter = new DateConverter();
-		sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+		sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
 	}
 			
 	@DataPoint public static String[]
-	set1 = {"2008-01-01", "2008-01-01 00:00:00.000"},
-	set2 = {"2008-02-01", "2008-02-01 00:00:00.000"},
-	set3 = {"2008-02-02", "2008-02-02 00:00:00.000"},
-	set4 = {"2008-02-02 15:40", "2008-02-02 15:40:00.000"},
-	set5 = {"2008-02-02 15:40:10", "2008-02-02 15:40:10.000"},
-	set6 = {"2008-02-02 15:40:10.423", "2008-02-02 15:40:10.423"};
+	set1 = {"2008-01-01", "2008-01-01T00:00:00.000"},
+	set2 = {"2008-02-01", "2008-02-01T00:00:00.000"},
+	set3 = {"2008-02-02", "2008-02-02T00:00:00.000"},
+	set4 = {"2008-02-02T15:40", "2008-02-02T15:40:00.000"},
+	set5 = {"2008-02-02T15:40:10", "2008-02-02T15:40:10.000"},
+	set6 = {"2008-02-02T15:40:10.423", "2008-02-02T15:40:10.423"};
 	
 	@Theory public void convert(String[] vals) throws ParseException {
 		Date d = sdf.parse(vals[1]);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message