ode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mr...@apache.org
Subject svn commit: r547752 - in /incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils: ISO8601DateParser.java xsd/XMLCalendar.java xsd/XSTypes.java
Date Fri, 15 Jun 2007 18:19:22 GMT
Author: mriou
Date: Fri Jun 15 11:19:22 2007
New Revision: 547752

URL: http://svn.apache.org/viewvc?view=rev&rev=547752
Log:
XMLCalendar is buggy, use ISO8601DateParser instead.

Removed:
    incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/xsd/XMLCalendar.java
Modified:
    incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/ISO8601DateParser.java
    incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/xsd/XSTypes.java

Modified: incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/ISO8601DateParser.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/ISO8601DateParser.java?view=diff&rev=547752&r1=547751&r2=547752
==============================================================================
--- incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/ISO8601DateParser.java (original)
+++ incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/ISO8601DateParser.java Fri
Jun 15 11:19:22 2007
@@ -19,6 +19,7 @@
 package org.apache.ode.utils;
 
 import java.text.SimpleDateFormat;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.TimeZone;
 
@@ -29,82 +30,89 @@
  */
 public class ISO8601DateParser {
 
-  public static Date parse(String date) throws java.text.ParseException {
-    String pattern;
-    StringBuffer buffer = new StringBuffer(date);
-    boolean timezoned = false;
-
-    switch (buffer.length()) {
-      case 4:
-        // Year: yyyy (eg 1997)
-        pattern = "yyyy";
-        break;
-      case 7:
-        // Year and month: yyyy-MM (eg 1997-07)
-        pattern = "yyyy-MM";
-        break;
-      case 10:
-        // Complete date: yyyy-MM-dd (eg 1997-07-16)
-        pattern = "yyyy-MM-dd";
-        break;
-      default:
-        // Complete date plus hours and minutes: yyyy-MM-ddTHH:mmTZD (eg 1997-07-16T19:20+01:00)
-        // Complete date plus hours, minutes and seconds: yyyy-MM-ddTHH:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
-        // Complete date plus hours, minutes, seconds and a decimal fraction of a second:
yyyy-MM-ddTHH:mm:ss.STZD (eg 1997-07-16T19:20:30.45+01:00)
-        pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS";
-
-        if (buffer.length() == 16) {
-          // add seconds
-          buffer.append(":00");
-        }
-        if (buffer.length() > 16 && buffer.charAt(16) != ':') {
-          // insert seconds
-          buffer.insert(16, ":00");
-        }
-        if (buffer.length() == 19) {
-          // add milliseconds
-          buffer.append(".000");
-        }
-        if (buffer.length() > 19 && buffer.charAt(19) != '.') {
-          // insert milliseconds
-          buffer.insert(19, ".000");
-        }
-        if (buffer.length() > 23) {
-          // append timezone
-          pattern = pattern + "Z";
-          timezoned = true;
-        }
-        if (buffer.length() == 24 && buffer.charAt(23) == 'Z') {
-          // replace 'Z' with '+0000'
-          buffer.replace(23, 24, "+0000");
-        }
-        if (buffer.length() == 29 && buffer.charAt(26) == ':') {
-          // delete '.' from 'HH:mm'
-          buffer.deleteCharAt(26);
-        }
+    public static Date parse(String date) throws java.text.ParseException {
+        String pattern;
+        StringBuffer buffer = new StringBuffer(date);
+        boolean timezoned = false;
+
+        switch (buffer.length()) {
+            case 4:
+                // Year: yyyy (eg 1997)
+                pattern = "yyyy";
+                break;
+            case 7:
+                // Year and month: yyyy-MM (eg 1997-07)
+                pattern = "yyyy-MM";
+                break;
+            case 10:
+                // Complete date: yyyy-MM-dd (eg 1997-07-16)
+                pattern = "yyyy-MM-dd";
+                break;
+            default:
+                // Complete date plus hours and minutes: yyyy-MM-ddTHH:mmTZD (eg 1997-07-16T19:20+01:00)
+                // Complete date plus hours, minutes and seconds: yyyy-MM-ddTHH:mm:ssTZD
(eg 1997-07-16T19:20:30+01:00)
+                // Complete date plus hours, minutes, seconds and a decimal fraction of a
second: yyyy-MM-ddTHH:mm:ss.STZD (eg 1997-07-16T19:20:30.45+01:00)
+                pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS";
+
+                if (buffer.length() == 16) {
+                    // add seconds
+                    buffer.append(":00");
+                }
+                if (buffer.length() > 16 && buffer.charAt(16) != ':') {
+                    // insert seconds
+                    buffer.insert(16, ":00");
+                }
+                if (buffer.length() == 19) {
+                    // add milliseconds
+                    buffer.append(".000");
+                }
+                if (buffer.length() > 19 && buffer.charAt(19) != '.') {
+                    // insert milliseconds
+                    buffer.insert(19, ".000");
+                }
+                if (buffer.length() > 23) {
+                    // append timezone
+                    pattern = pattern + "Z";
+                    timezoned = true;
+                }
+                if (buffer.length() == 24 && buffer.charAt(23) == 'Z') {
+                    // replace 'Z' with '+0000'
+                    buffer.replace(23, 24, "+0000");
+                }
+                if (buffer.length() == 29 && buffer.charAt(26) == ':') {
+                    // delete '.' from 'HH:mm'
+                    buffer.deleteCharAt(26);
+                }
+        }
+
+        // always set time zone on formatter
+        SimpleDateFormat format = new SimpleDateFormat(pattern);
+        if (timezoned) format.setTimeZone(TimeZone.getTimeZone("UTC"));
+
+        return format.parse(buffer.toString());
     }
 
-    // always set time zone on formatter
-    SimpleDateFormat format = new SimpleDateFormat(pattern);
-    if (timezoned) format.setTimeZone(TimeZone.getTimeZone("UTC"));
-
-    return format.parse(buffer.toString());
-  }
-
-  public static String format( Date date ) {
-    TimeZone timeZone = TimeZone.getDefault();
-    boolean utc = TimeZone.getTimeZone("UTC").equals(timeZone) || TimeZone.getTimeZone("GMT").equals(timeZone);
-
-    String pattern = utc ? "yyyy-MM-dd'T'HH:mm:ss'Z'" : "yyyy-MM-dd'T'HH:mm:ssZ";
-    SimpleDateFormat format = new SimpleDateFormat(pattern);
-    format.setTimeZone(timeZone);
-
-    StringBuffer buffer = new StringBuffer(format.format(date));
-    if (!utc) {
-      buffer.insert(buffer.length() - 2, ':');
+    public static Calendar parseCal(String date) throws java.text.ParseException {
+        Date d = parse(date);
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(d);
+        return cal;
     }
 
-    return buffer.toString();
-  }
+    public static String format( Date date ) {
+        TimeZone timeZone = TimeZone.getDefault();
+        boolean utc = TimeZone.getTimeZone("UTC").equals(timeZone) || TimeZone.getTimeZone("GMT").equals(timeZone);
+
+        String pattern = utc ? "yyyy-MM-dd'T'HH:mm:ss'Z'" : "yyyy-MM-dd'T'HH:mm:ssZ";
+        SimpleDateFormat format = new SimpleDateFormat(pattern);
+        format.setTimeZone(timeZone);
+
+        StringBuffer buffer = new StringBuffer(format.format(date));
+        if (!utc) {
+            buffer.insert(buffer.length() - 2, ':');
+        }
+
+        return buffer.toString();
+    }
 
 }

Modified: incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/xsd/XSTypes.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/xsd/XSTypes.java?view=diff&rev=547752&r1=547751&r2=547752
==============================================================================
--- incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/xsd/XSTypes.java (original)
+++ incubator/ode/trunk/utils/src/main/java/org/apache/ode/utils/xsd/XSTypes.java Fri Jun
15 11:19:22 2007
@@ -19,6 +19,8 @@
 
 package org.apache.ode.utils.xsd;
 
+import org.apache.ode.utils.ISO8601DateParser;
+
 import javax.xml.namespace.QName;
 
 /**
@@ -44,7 +46,7 @@
         return Double.valueOf(value);
       } else if (isDate(type)) {
         foundType = "date";
-        return new XMLCalendar(value);
+        return ISO8601DateParser.parseCal(value);
       } else if (isString(type)) {
         foundType = "string";
         return value;



Mime
View raw message