Issue 441 - return EvalError if we can't parse a date
git-svn-id: http://google-refine.googlecode.com/svn/trunk@2237 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
131ff81c0d
commit
ebede9b424
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
Copyright 2010, Google Inc.
|
Copyright 2010,2011. Google Inc.
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
@ -42,6 +42,7 @@ import java.util.Properties;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.google.refine.expr.EvalError;
|
||||||
import com.google.refine.expr.util.CalendarParser;
|
import com.google.refine.expr.util.CalendarParser;
|
||||||
import com.google.refine.expr.util.CalendarParserException;
|
import com.google.refine.expr.util.CalendarParserException;
|
||||||
import com.google.refine.grel.Function;
|
import com.google.refine.grel.Function;
|
||||||
@ -61,7 +62,7 @@ public class ToDate implements Function {
|
|||||||
return ((Calendar) arg0).getTime();
|
return ((Calendar) arg0).getTime();
|
||||||
} else if (!(arg0 instanceof String)) {
|
} else if (!(arg0 instanceof String)) {
|
||||||
// ignore cell values that aren't strings
|
// ignore cell values that aren't strings
|
||||||
return null;
|
return new EvalError("Not a String - cannot parse to date");
|
||||||
}
|
}
|
||||||
String o1 = (String) arg0;
|
String o1 = (String) arg0;
|
||||||
|
|
||||||
@ -74,7 +75,7 @@ public class ToDate implements Function {
|
|||||||
try {
|
try {
|
||||||
return CalendarParser.parse( o1, (month_first) ? CalendarParser.MM_DD_YY : CalendarParser.DD_MM_YY);
|
return CalendarParser.parse( o1, (month_first) ? CalendarParser.MM_DD_YY : CalendarParser.DD_MM_YY);
|
||||||
} catch (CalendarParserException e) {
|
} catch (CalendarParserException e) {
|
||||||
// do something about
|
return new EvalError("Cannot parse to date");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +92,7 @@ public class ToDate implements Function {
|
|||||||
try {
|
try {
|
||||||
date = formatter.parse(o1);
|
date = formatter.parse(o1);
|
||||||
} catch (java.text.ParseException e) {
|
} catch (java.text.ParseException e) {
|
||||||
// ignore
|
return new EvalError("Cannot parse to date");
|
||||||
}
|
}
|
||||||
if (date != null) {
|
if (date != null) {
|
||||||
GregorianCalendar c = new GregorianCalendar();
|
GregorianCalendar c = new GregorianCalendar();
|
||||||
|
Loading…
Reference in New Issue
Block a user