Make copy of Calendar object before modifying it. Also handle Date type.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@1982 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
4d84733b8e
commit
44652a3ee2
@ -34,6 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
package com.google.refine.expr.functions.date;
|
package com.google.refine.expr.functions.date;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
@ -47,10 +48,17 @@ public class Inc implements Function {
|
|||||||
|
|
||||||
public Object call(Properties bindings, Object[] args) {
|
public Object call(Properties bindings, Object[] args) {
|
||||||
if (args.length == 3 &&
|
if (args.length == 3 &&
|
||||||
args[0] != null && args[0] instanceof Calendar &&
|
args[0] != null && (args[0] instanceof Calendar || args[0] instanceof Date) &&
|
||||||
args[1] != null && args[1] instanceof Number &&
|
args[1] != null && args[1] instanceof Number &&
|
||||||
args[2] != null && args[2] instanceof String) {
|
args[2] != null && args[2] instanceof String) {
|
||||||
Calendar date = (Calendar) args[0];
|
Calendar date;
|
||||||
|
if (args[0] instanceof Calendar) {
|
||||||
|
date = (Calendar) ((Calendar) args[0]).clone(); // must copy so not to modify original
|
||||||
|
} else {
|
||||||
|
date = Calendar.getInstance();
|
||||||
|
date.setTime((Date) args[0]);
|
||||||
|
}
|
||||||
|
|
||||||
int amount = ((Number) args[1]).intValue();
|
int amount = ((Number) args[1]).intValue();
|
||||||
String unit = (String) args[2];
|
String unit = (String) args[2];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user