Issue 184 - use default locale date formatting if no format string is specified

git-svn-id: http://google-refine.googlecode.com/svn/trunk@1932 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Tom Morris 2010-11-26 23:47:09 +00:00
parent 080ec5332e
commit c7b0f4d024

View File

@ -33,6 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.google.refine.expr.functions; package com.google.refine.expr.functions;
import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Properties; import java.util.Properties;
@ -49,13 +50,17 @@ public class ToString implements Function {
Object o1 = args[0]; Object o1 = args[0];
if (o1 != null) { if (o1 != null) {
if (o1 instanceof Calendar) { if (o1 instanceof Calendar) {
DateFormat formatter = null;
if (args.length == 2) { if (args.length == 2) {
Object o2 = args[1]; Object o2 = args[1];
if (o2 != null && o2 instanceof String) { if (o2 != null && o2 instanceof String) {
SimpleDateFormat formatter = new SimpleDateFormat((String) o2); formatter = new SimpleDateFormat((String) o2);
}
}
if (formatter == null) {
formatter = DateFormat.getDateInstance();
}
return formatter.format(((Calendar) o1).getTime()); return formatter.format(((Calendar) o1).getTime());
}
}
} else { } else {
return (o1 instanceof String) ? o1 : o1.toString(); return (o1 instanceof String) ? o1 : o1.toString();
} }