in impl/src/main/java/org/apache/tuscany/sdo/helper/DataHelperImpl.java [49:135]
public synchronized Date toDate(String dateString)
{
if (dateString == null)
{
return null;
}
SDOSimpleDateFormat format;
Date result = null;
boolean negative = false;
String formatString;
dateString = dateString.trim();
// Determine if it is a negative Date, DateTime, or Duration
if (dateString.length() > 2 && dateString.charAt(0) == '-' && dateString.charAt(1) != '-')
{
negative = true;
dateString = dateString.substring(1);
}
// SDO Date Format ends with a Z
if (dateString.endsWith("Z"))
{
if (dateString.indexOf('.') != -1)
formatString = new String("yyyy-MM-dd'T'HH:mm:ss'.'S'Z'");
else
formatString = new String ("yyyy-MM-dd'T'HH:mm:ss'Z'");
format = new SDOSimpleDateFormat(formatString);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
result = checkFormat(dateString, format);
// If no match, continue to try further possibilities
if (result != null)
{
if (negative)
return handleBCE(result);
else
return result;
}
}
// Duration format begins with a P
if (dateString.startsWith("P"))
{
// Remove any spaces in the dateString
String durationString = dateString.replaceAll(" ", "");
// Build the formatString based on the contents of dateString
formatString = obtainDurationFormats(durationString);
format = new SDOSimpleDateFormat(formatString);
result = checkFormat(durationString, format);
if (result != null)
{
if (negative)
return handleNegative(result);
else
return result;
}
}
formatString = obtainSpecificFormat(dateString);
if (formatString != null)
{
format = new SDOSimpleDateFormat(formatString);
result = checkFormat(dateString, format);
if (result != null)
{
if (negative)
return handleBCE(result);
else
return result;
}
}
return null;
}