Locale locale = (Locale) context.get("locale");
if (locale == null) {
locale = Locale.getDefault();
}
StringToTimestamp stringToTimestamp = new DateTimeConverters.StringToTimestamp();
Timestamp timestamp = null;
try {
timestamp = stringToTimestamp.convert(retVal);
Date date = new Date(timestamp.getTime());
DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.SHORT, locale);
retVal = dateFormatter.format(date);
}
catch (ConversionException e) {
String errMsg = "Error formatting date using default instead [" + retVal + "]: " + e.toString();
Debug.logError(e, errMsg, module);
// create default date value from timestamp string
retVal = retVal.substring(0,10);
}
} else if ("date-time".equals(this.type) && retVal.length() > 16) {
Locale locale = (Locale) context.get("locale");
TimeZone timeZone = (TimeZone) context.get("timeZone");
if (locale == null) {
locale = Locale.getDefault();
}
if (timeZone == null) {
timeZone = TimeZone.getDefault();
}
StringToTimestamp stringToTimestamp = new DateTimeConverters.StringToTimestamp();
Timestamp timestamp = null;
try {
timestamp = stringToTimestamp.convert(retVal);
Date date = new Date(timestamp.getTime());
DateFormat dateFormatter = UtilDateTime.toDateTimeFormat(null, timeZone, locale);
retVal = dateFormatter.format(date);
}