abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From calav...@apache.org
Subject svn commit: r696802 - /incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/AtomDate.java
Date Thu, 18 Sep 2008 21:03:32 GMT
Author: calavera
Date: Thu Sep 18 14:03:32 2008
New Revision: 696802

URL: http://svn.apache.org/viewvc?rev=696802&view=rev
Log:
fixes ABDERA-199: AtomDate does not check for Date Constructs having T & Z separations
between Date and Time. Thanks to Amit Surana.

Test1:
Input: AtomDate.parse("2008-09-08A20:00:00Z+05:30")
Output: Exception

Test2:
Input: AtomDate.parse("2008-09-08T20:00:00X+05:30")
Output: Exception

Test3:
Input: AtomDate.parse("2008-09-08T20:00:00Z+05:30")
Output: Mon Sep 08 20:00:00 IST 2008 //EXPECTED OUTCOME


Modified:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/AtomDate.java

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/AtomDate.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/AtomDate.java?rev=696802&r1=696801&r2=696802&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/AtomDate.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/AtomDate.java Thu
Sep 18 14:03:32 2008
@@ -225,7 +225,7 @@
   }
   
   private static final Pattern PATTERN = Pattern.compile(
-    "(\\d{4})(?:-(\\d{2}))?(?:-(\\d{2}))?(?:[Tt](?:(\\d{2}))?(?::(\\d{2}))?(?::(\\d{2}))?(?:\\.(\\d{3}))?)?([Zz])?(?:([+-])(\\d{2}):(\\d{2}))?");
+    "(\\d{4})(?:-(\\d{2}))?(?:-(\\d{2}))?(?:([Tt])?(?:(\\d{2}))?(?::(\\d{2}))?(?::(\\d{2}))?(?:\\.(\\d{3}))?)?([Zz])?(?:([+-])(\\d{2}):(\\d{2}))?");
    
   /**
    * Parse the serialized string form into a java.util.Date
@@ -235,20 +235,22 @@
   public static Date parse(String date) {
     Matcher m = PATTERN.matcher(date);
     if (m.find()) {
+    	if(m.group(4)==null || m.group(9)==null) 
+    		throw new IllegalArgumentException("Invalid Date Format");
       Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
       int hoff = 0, moff = 0, doff = -1;
-      if (m.group(9) != null) {
-        doff = m.group(9).equals("-") ? 1 : -1;
-        hoff = doff * (m.group(10) != null ? Integer.parseInt(m.group(10)) : 0);
-        moff = doff * (m.group(11) != null ? Integer.parseInt(m.group(11)) : 0);
+      if (m.group(10) != null) {
+        doff = m.group(10).equals("-") ? 1 : -1;
+        hoff = doff * (m.group(11) != null ? Integer.parseInt(m.group(11)) : 0);
+        moff = doff * (m.group(12) != null ? Integer.parseInt(m.group(12)) : 0);
       }
       c.set(Calendar.YEAR,        Integer.parseInt(m.group(1)));
       c.set(Calendar.MONTH,       m.group(2) != null ? Integer.parseInt(m.group(2))-1 : 0);
       c.set(Calendar.DATE,        m.group(3) != null ? Integer.parseInt(m.group(3)) : 1);
-      c.set(Calendar.HOUR_OF_DAY, m.group(4) != null ? Integer.parseInt(m.group(4)) + hoff:
0);
-      c.set(Calendar.MINUTE,      m.group(5) != null ? Integer.parseInt(m.group(5)) + moff:
0);
-      c.set(Calendar.SECOND,      m.group(6) != null ? Integer.parseInt(m.group(6)) : 0);
-      c.set(Calendar.MILLISECOND, m.group(7) != null ? Integer.parseInt(m.group(7)) : 0);
+      c.set(Calendar.HOUR_OF_DAY, m.group(5) != null ? Integer.parseInt(m.group(5)) + hoff:
0);
+      c.set(Calendar.MINUTE,      m.group(6) != null ? Integer.parseInt(m.group(6)) + moff:
0);
+      c.set(Calendar.SECOND,      m.group(7) != null ? Integer.parseInt(m.group(7)) : 0);
+      c.set(Calendar.MILLISECOND, m.group(8) != null ? Integer.parseInt(m.group(8)) : 0);
       return c.getTime();
     } else {
       throw new IllegalArgumentException("Invalid Date Format");



Mime
View raw message