I have a couple of questions related to Date formats:

1)  Date, DateTime, and Duration all have an optional leading hyphen (As
seen in the table on the bottom of page 72 of the SDO spec.).  Should the
presence or absence of this hyphen have an effect on how a String is
interpretted as a Date, DateTime, or Duration?

      On page 74 of the spec, a SimpleDateFormat is given that should be
sufficient for converting from String to Date.  Using this format, the
inclusion of the optional leading hyphen does have an effect - as is shown
by the following method:

   public void testSpec()
   {
       SimpleDateFormat f = new
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'SSSz");
       try
       {
          String dateString = "2006-08-17T04:45:55.9EDT";
          System.out.println(f.parse(dateString.replaceFirst("([+\\-]..):",
"$1")));
          dateString = "-2006-08-17T04:45:55.9EDT";
          System.out.println(f.parse(dateString.replaceFirst("([+\\-]..):",
"$1")));
          dateString = "2007-08-17T04:45:55.9EST";
          System.out.println(f.parse(dateString.replaceFirst("([+\\-]..):",
"$1")));
          dateString = "-2007-08-17T04:45:55.9EST";
          System.out.println(f.parse(dateString.replaceFirst("([+\\-]..):",
"$1")));
       }
       catch (Exception e) {}

       SimpleDateFormat duration = new SimpleDateFormat("'P'yyyy'Y' MM'M'
dd'D T' HH'H' mm'M' ss'S.'S");
       try
       {
           String dateString = "P2006Y 08M 17D T 04H 45M 55S.854";
           System.out.println(duration.parse(dateString));
           dateString = "-P2008Y 09M 13D T 04H 45M 55S.854";
           System.out.println(duration.parse(dateString));
       }
       catch (Exception e) { System.out.println("Exception thrown");}
   }

Here is the output:

Thu Aug 17 04:45:55 EDT 2006
Sun Aug 17 03:45:55 EST 2007
Thu Aug 17 05:45:55 EDT 2007
Sun Aug 17 04:45:55 EST 2008
Thu Aug 17 04:45:55 EDT 2006
Exception thrown

Note that the inclusion of the optional leading '-' has the following
effects:
*  Increments the year.
*  Prevents the handling of Daylight Savings Time.  (I verified this in BST
by changing my laptop's time zone to Brasilia, and the month to February in
the method.)
*  For the case of Duration, prevents the string from being parsed.

Given this behavior by SimpleDateFormat - should DataHelper accomodate?  (
I.e. Should DataHelperImpl.java be written to explicity remove leading '-'
for Date, DateTime and Duration strings?)  Or is the above behavior (the
three asterisks) desirable and expected?  I have already made changes to
DataHelperImpl.java for Tuscany-582 and could easily incorporate the
additional work.

2)  What is the intent of the replaceFirst found in the specification with
regard to converting String to Date?

The replaceFirst I'm speaking of is on page 74 of the 2.1 SDO Specification:

 The following example use of java.text.SimpleDateFormat is compliant for
converting String to Date when all fields are present:

 DateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'SSSz");
 Date date = f.parse(dateString.replaceFirst("([+\\-]..):", "$1"));

I was curious so I wrote the following method:

   public void testSpec()
   {
       String [] array = {"+ab:blah", "-ab:blah", "\\ab:blah",
"+ab:blah+ab:blah",
              "++ab:blah", "+++:blah", "2006-08-17T04:45:55.9EDT"};

       for (int i = 0; i < array.length; i++)
       {
           System.out.println(array[i] + " --> " +
array[i].replaceFirst("([+\\-]..):", "$1"));
       }
  }

Here is the output

+ab:blah --> +abblah
-ab:blah --> -abblah
\ab:blah --> \ab:blah
+ab:blah+ab:blah --> +abblah+ab:blah
++ab:blah --> ++abblah
+++:blah --> +++blah
2006-08-17T04:45:55.9EDT --> 2006-08-17T04:45:55.9EDT

It has no impact on a string of the expected format.  Also, the intent seems
to be to have the same effect for +, -, and \, however in the third line it
seems '\' is treated differently than '+' or '-'.  And again, I don't
understand the intent.  Can somebody please explain?

Reply via email to