Return "null" for toString(null) - fixes #783

- also fixed grammar in error message
This commit is contained in:
Tom Morris 2013-09-18 10:20:17 -04:00
parent daed3bd90c
commit f344e3da1c
2 changed files with 4 additions and 2 deletions

View File

@ -63,12 +63,12 @@ public class ToString implements Function {
} else if (args.length == 1) { } else if (args.length == 1) {
if (o1 instanceof String) { if (o1 instanceof String) {
return (String) o1; return (String) o1;
} else if (o1 != null) { } else {
return StringUtils.toString(o1); return StringUtils.toString(o1);
} }
} }
} }
return new EvalError("ToString accepts an object an optional second argument containing a date format string"); return new EvalError("ToString accepts an object and an optional second argument containing a date format string");
} }

View File

@ -16,6 +16,8 @@ public class StringUtils {
if (o instanceof Calendar || o instanceof Date) { if (o instanceof Calendar || o instanceof Date) {
DateFormat formatter = DateFormat.getDateInstance(); DateFormat formatter = DateFormat.getDateInstance();
return formatter.format(o instanceof Date ? ((Date) o) : ((Calendar) o).getTime()); return formatter.format(o instanceof Date ? ((Date) o) : ((Calendar) o).getTime());
} else if (o == null) {
return "null";
} else { } else {
return o.toString(); return o.toString();
} }