From 44652a3ee2b3618153a3bda2c5e4a1a995051915 Mon Sep 17 00:00:00 2001 From: David Huynh Date: Mon, 10 Jan 2011 23:06:28 +0000 Subject: [PATCH] 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 --- .../com/google/refine/expr/functions/date/Inc.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/main/src/com/google/refine/expr/functions/date/Inc.java b/main/src/com/google/refine/expr/functions/date/Inc.java index 436dea95f..cbf178560 100644 --- a/main/src/com/google/refine/expr/functions/date/Inc.java +++ b/main/src/com/google/refine/expr/functions/date/Inc.java @@ -34,6 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.expr.functions.date; import java.util.Calendar; +import java.util.Date; import java.util.Properties; import org.json.JSONException; @@ -47,10 +48,17 @@ public class Inc implements Function { public Object call(Properties bindings, Object[] args) { 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[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(); String unit = (String) args[2];