[ 
http://issues.apache.org/jira/browse/TUSCANY-579?page=comments#action_12424242 
] 
            
Fuhwei Lwo commented on TUSCANY-579:
------------------------------------

Brian,

I don't think your patch would work. Below is a small non-SDO test program that 
would prove your format string won't work because the dateStr won't be equal to 
dateStr2 after round trip conversion. The hour will miss one digit. The Z time 
zone will be gone too.  Also, your date will be way off across different time 
zones. Note the SDO Date type is based on the Zulu time zone.

import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.ParseException;

public class TestSDODate2StringConversion {
        public static void main(String[] args) {
                String dateStr = "2006-03-31T03:30:45.123Z";

                // Convert String to Date type
                SimpleDateFormat sdf = new 
SimpleDateFormat("yy'-'MM'-'dd'T'H':'mm':'ss.S");
                Date date = null;
                try {
                        date = sdf.parse(dateStr);
                        System.out.println("Date: " + date);
                }
                catch (ParseException e) {
                        e.printStackTrace();
                }

                // Convert Date to String type
                SimpleDateFormat sdf2 = new 
SimpleDateFormat("yyyy'-'MM'-'dd'T'H':'mm':'ss.S");
                String dateStr2 = sdf2.format(date);
                System.out.println("Date string: " + dateStr2);
        }
}


> getString on Date field results in IllegalArgumentException
> -----------------------------------------------------------
>
>                 Key: TUSCANY-579
>                 URL: http://issues.apache.org/jira/browse/TUSCANY-579
>             Project: Tuscany
>          Issue Type: Bug
>          Components: Java SDO Implementation
>            Reporter: Brian Murray
>         Assigned To: Frank Budinsky
>         Attachments: Tuscany579.patch
>
>
> On page 146 of V2.01 of the spec, it is stated that conversion from Date to 
> String is supported.  However, getString on Date type results in an 
> IllegalArgumentException.  Here is a code segment:
>       public void testShowErrorsInSimpleFormat() throws Exception
>       {
>             DataObject test_obj = DataFactory.INSTANCE.create(API_TEST_TYPE);
>             Date current_date = new Date(System.currentTimeMillis());
>             // getString does not work on Date type
>             test_obj.setDate("dateVal", current_date);
>             String returned_string = test_obj.getString("dateVal"); //Gives 
> IllegalArgumentException
>       }
>    And here is the XSD:
>       <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
>       xmlns:sdo="commonj.sdo"
>       xmlns:simple="http://www.example.com/api_test";
>       targetNamespace="http://www.example.com/api_test";>
>       <xsd:import namespace="commonj.sdo" schemaLocation="sdoModel.xsd"/>
>       <xsd:element name="apiTestElem" type="simple:APITest"/>
>       <xsd:complexType mixed="true" name="APITest">
>       <xsd:sequence>
>             <xsd:element name="stringVal" type="sdo:String"/>
>             <xsd:element name="booleanVal" type="sdo:Boolean"/>
>             <xsd:element name="booleanVal2" type="sdo:Boolean"/>
>             <xsd:element name="byteVal" type="sdo:Byte"/>
>             <xsd:element name="stringVal2" type="sdo:String"/>
>             <xsd:element name="decimalVal" type="sdo:Decimal"/>
>             <xsd:element name="decimalVal2" type="sdo:Decimal"/>
>             <xsd:element name="intVal" type="sdo:Int"/>
>             <xsd:element name="floatVal" type="sdo:Float"/>
>             <xsd:element name="doubleVal" type="sdo:Double"/>
>             <xsd:element name="dateVal" type="sdo:Date"/>
>             <xsd:element name="shortVal" type="sdo:Short"/>
>             <xsd:element name="longVal" type="sdo:Long"/>
>             <xsd:element maxOccurs="unbounded" minOccurs="0"
>    name="children" type="simple:APITest"/>
>             <xsd:element name="bytesVal" type="sdo:Bytes"/>
>             <xsd:element name="integerVal" type="sdo:Integer"/>
>             <xsd:element name="charVal" type="sdo:Character"/>
>       </xsd:sequence>
>    </xsd:complexType>
> I originally thought that also getDate was not working on String, but this 
> was an error in my test case.  I had been setting the String value to be 
> Date.toString().  Fuhwei correctly pointed out that the String format that 
> would allow conversion is given on page 72 of the specification and is 
> different than what is returned by Date.toString().  I have tested with the 
> correct String format and found that getDate works, so clearly this is not an 
> error.  However, I wonder if it would be a good idea to aditionally support 
> the String format that results from Date.toString().

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to