package com.occamlab.te.util;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.ISODateTimeFormat;

/**
 * Functions to convert various dates and times to a standard DateTime string.
 * 
 * @author jparrpearson
 */
public class DateTimeConverter {


	public DateTimeConverter() {
	}

	/**
	 * Creats a DateTime object and adds any necessary default information to the input string
	 * 
	 * @param dateTimeStr
	 *            a string representing a date/time
	 */
	public String getDateTimeValue(String dateTimeStr) {
		
		DateTimeFormatter formatter = ISODateTimeFormat.dateOptionalTimeParser();
		DateTime dateTime = null;
		try {
			dateTime = formatter.parseDateTime(dateTimeStr);
		} catch (Exception e) {
			System.out.println("DateTimeConverter ERROR: "+e.getMessage());
		}

		return dateTime.toString();
	}

	public static void main(String[] args) {
		DateTimeConverter dateTimeConverter = new DateTimeConverter();
		String result = dateTimeConverter.getDateTimeValue(args[0]);
		System.out.println(result);
	}
}
@@ -24,16 +24,82 @@
 .util;%0A%0A
+import java.util.regex.Pattern;%0D%0Aimport java.util.regex.Matcher;%0A%0A
 import o
@@ -122,16 +122,16 @@
 eTime;%0D%0A
-
 import o
@@ -682,16 +682,849 @@
 tr) %7B%0A%09%09
+%0A%09%09// Ensure the string is in proper ISO form (make adjustments from XML-syntax)%0A%09%09if (dateTimeStr.endsWith(%22Z%22)) %7B%0A%09%09%09// No 'T' even though it ends with a 'Z', so add one%0A%09%09%09if (dateTimeStr.indexOf(%22T%22) == -1) %7B%0A%09%09%09%09StringBuffer buf = new StringBuffer(dateTimeStr);%0A%09%09%09%09int lastZ = buf.lastIndexOf(%22Z%22);%0A%09%09%09%09buf.insert(lastZ, %22T%22);%0A%09%09%09%09dateTimeStr = buf.toString();%0A%09%09%09%7D%0A%09%09%7D%0A%09%09Pattern pattern = Pattern.compile(%22.*%5B+-%5D%5C%5Cd%7B2%7D:%5C%5Cd%7B2%7D%22);%0A%09%09Matcher matcher = pattern.matcher(dateTimeStr);%0A%09%09if (matcher.matches()) %7B%0A%09%09%09// There is a timezone, but no 'T', so add one%0A%09%09%09if (dateTimeStr.indexOf(%22T%22) == -1) %7B%0A%09%09%09%09StringBuffer buf = new StringBuffer(dateTimeStr);%0A%09%09%09%09int lastColon = buf.lastIndexOf(%22:%22);%0A%09%09%09%09buf.insert(lastColon-3, %22T%22);%0A%09%09%09%09dateTimeStr = buf.toString();%0A%09%09%09%7D%0A%09%09%7D%09%09%0A%09%09%09%09%0A%09%09// Create a formatter to parse the input string
 %0D%0A%09%09Date
@@ -1629,16 +1629,80 @@
 %09%09try %7B%0A
+%09%09%09// Format the input string as a ISO standard DateTime string%0A
 %09%09%09dateT
@@ -1842,12 +1842,11 @@
 ));%0A
+
 %09%09%7D
-%0D
 %0A%0A%09%09

Fix to DateTimeConverter to modify the incoming dateTime string to proper ISO (from XML schema syntax)