tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adrianocrest...@apache.org
Subject svn commit: r643224 - in /incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper: DataHelperImpl.java SDOSimpleDateFormat.java
Date Tue, 01 Apr 2008 00:14:02 GMT
Author: adrianocrestani
Date: Mon Mar 31 17:14:00 2008
New Revision: 643224

URL: http://svn.apache.org/viewvc?rev=643224&view=rev
Log:
fixing bug described on TUSCANY-1659

Added:
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOSimpleDateFormat.java
Modified:
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/DataHelperImpl.java

Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/DataHelperImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/DataHelperImpl.java?rev=643224&r1=643223&r2=643224&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/DataHelperImpl.java
(original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/DataHelperImpl.java
Mon Mar 31 17:14:00 2008
@@ -22,7 +22,6 @@
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.text.ParseException;
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
@@ -54,7 +53,7 @@
       return null;
     }
       
-    SimpleDateFormat format;
+    SDOSimpleDateFormat format;
     Date result = null;
     boolean negative = false;
     String formatString;
@@ -77,7 +76,7 @@
       else
         formatString = new String ("yyyy-MM-dd'T'HH:mm:ss'Z'");
         
-      format = new SimpleDateFormat(formatString);
+      format = new SDOSimpleDateFormat(formatString);
       format.setTimeZone(TimeZone.getTimeZone("UTC"));
       
       result = checkFormat(dateString, format);
@@ -105,7 +104,7 @@
       // Build the formatString based on the contents of dateString
         
       formatString = obtainDurationFormats(durationString);
-      format = new SimpleDateFormat(formatString);
+      format = new SDOSimpleDateFormat(formatString);
       result = checkFormat(durationString, format);
       if (result != null)
       {     
@@ -120,7 +119,7 @@
 
     if (formatString != null)
     {
-      format = new SimpleDateFormat(formatString);
+      format = new SDOSimpleDateFormat(formatString);
       result = checkFormat(dateString, format); 
 
       if (result != null)
@@ -135,12 +134,12 @@
     return null;
   }
   
-  private synchronized Date checkFormat(String dateString, SimpleDateFormat format)
+  private synchronized Date checkFormat(String dateString, SDOSimpleDateFormat format)
   {
     String formatPattern = format.toPattern();
     StringBuffer addedFields = new StringBuffer();
     String fieldsString, parseString;
-    SimpleDateFormat compositeFormat;
+    SDOSimpleDateFormat compositeFormat;
     Date dateValue;
 
     // For certain permissable input strings (e.g. those resulting from toYear
@@ -176,7 +175,7 @@
     
     else
     {
-      compositeFormat = new SimpleDateFormat(fieldsString);
+      compositeFormat = new SDOSimpleDateFormat(fieldsString);
       dateValue = new Date(System.currentTimeMillis());
       parseString = compositeFormat.format(dateValue) + dateString;    
       compositeFormat.applyPattern(fieldsString + formatPattern);
@@ -354,7 +353,7 @@
       return null;
     }
     
-    SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'SSS'Z'");
+    SDOSimpleDateFormat f = new SDOSimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'SSS'Z'");
     f.setTimeZone(TimeZone.getTimeZone("UTC"));
     
     return f.format(date);
@@ -367,7 +366,7 @@
       return null;
     }
     
-    SimpleDateFormat f = new SimpleDateFormat("'P'yyyy'Y' MM'M' dd'D' 'T' HH'H' mm'M' ss'S.'SSS");
+    SDOSimpleDateFormat f = new SDOSimpleDateFormat("'P'yyyy'Y' MM'M' dd'D' 'T' HH'H' mm'M'
ss'S.'SSS");
     
     return f.format(date);
   }
@@ -379,7 +378,7 @@
       return null;
     }
     
-    SimpleDateFormat f = new SimpleDateFormat("HH:mm:ss'.'SSS zz");
+    SDOSimpleDateFormat f = new SDOSimpleDateFormat("HH:mm:ss'.'SSS zz");
     
     return f.format(date);
   }
@@ -391,7 +390,7 @@
       return null;
     }
     
-    SimpleDateFormat f = new SimpleDateFormat("---dd zz");
+    SDOSimpleDateFormat f = new SDOSimpleDateFormat("---dd zz");
     
     return f.format(date);
   }
@@ -403,7 +402,7 @@
       return null;
     }
     
-    SimpleDateFormat f = new SimpleDateFormat("--MM zz");
+    SDOSimpleDateFormat f = new SDOSimpleDateFormat("--MM zz");
     
     return f.format(date);
   }
@@ -415,7 +414,7 @@
       return null;
     }
     
-    SimpleDateFormat f = new SimpleDateFormat("--MM-dd zz");
+    SDOSimpleDateFormat f = new SDOSimpleDateFormat("--MM-dd zz");
     
     return f.format(date);
   }
@@ -427,7 +426,7 @@
       return null;
     }
     
-    SimpleDateFormat f = new SimpleDateFormat("yyyy zz");
+    SDOSimpleDateFormat f = new SDOSimpleDateFormat("yyyy zz");
     
     return f.format(date); 
   }
@@ -439,7 +438,7 @@
       return null;
     }
     
-    SimpleDateFormat f = new SimpleDateFormat("yyyy-MM zz");
+    SDOSimpleDateFormat f = new SDOSimpleDateFormat("yyyy-MM zz");
     
     return f.format(date);
   }
@@ -451,7 +450,7 @@
       return null;
     }
     
-    SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd zz");
+    SDOSimpleDateFormat f = new SDOSimpleDateFormat("yyyy-MM-dd zz");
     
     return f.format(date);
   }

Added: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOSimpleDateFormat.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOSimpleDateFormat.java?rev=643224&view=auto
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOSimpleDateFormat.java
(added)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOSimpleDateFormat.java
Mon Mar 31 17:14:00 2008
@@ -0,0 +1,92 @@
+/**
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.tuscany.sdo.helper;
+
+import java.text.DateFormatSymbols;
+import java.text.SimpleDateFormat;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * Fixes the bug reported at JIRA TUSCANY-1659
+ * This class ensures the time zone will be formatted as the abbreviation format.
+ */
+public class SDOSimpleDateFormat extends SimpleDateFormat {
+	
+	private static final long serialVersionUID = 2519728288048681529L;
+	
+	public SDOSimpleDateFormat() {
+		super();
+		setTimeZone(getTimeZone());
+		
+	}
+	
+	public SDOSimpleDateFormat(String pattern) {
+		super(pattern);
+		setTimeZone(getTimeZone());
+		
+	}
+	
+	public SDOSimpleDateFormat(String pattern, Locale locale) {
+		super(pattern, locale);
+		setTimeZone(getTimeZone());
+		
+	}
+	
+	public SDOSimpleDateFormat(String pattern, DateFormatSymbols formatSymbols) {
+		super(pattern, formatSymbols);
+		setTimeZone(getTimeZone());
+		
+	}
+
+	/**
+	 * Overrides the SimpleDateFormat.setTimeZone(TimeZone) method. 
+	 * It checks if the TimeZone to be set is in the abbreviation format. 
+	 * If not, it looks for its abbreviation format and set it.  
+	 * 
+	 * @param timeZone the time zone to be set
+	 * 
+	 */
+	public void setTimeZone(TimeZone timeZone) {
+		
+		if (timeZone.getID().length() != 3) {
+			String[] timeZoneNames = TimeZone.getAvailableIDs(timeZone.getRawOffset());
+			
+			for (int i = 0 ; i < timeZoneNames.length ; i++ ) {
+				String actualTimeZoneName = timeZoneNames[i].trim();
+				
+				// if the time zone name has 3 letters and ends with a T character, 
+				// it's considered to be the abbreviation format
+				if (actualTimeZoneName.length() == 3 && actualTimeZoneName.charAt(actualTimeZoneName.length()
- 1) == 'T') {
+					timeZone = TimeZone.getTimeZone(timeZoneNames[i]);
+					break;
+					
+				}
+				
+			}
+			
+		}
+		
+		super.setTimeZone(timeZone);
+		
+	}
+
+}



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


Mime
View raw message