diff --git a/main/src/com/google/refine/expr/functions/ToDate.java b/main/src/com/google/refine/expr/functions/ToDate.java index 2eecfe4b8..2466bd676 100644 --- a/main/src/com/google/refine/expr/functions/ToDate.java +++ b/main/src/com/google/refine/expr/functions/ToDate.java @@ -37,6 +37,7 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.time.OffsetDateTime; import java.time.ZoneOffset; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Date; import java.util.GregorianCalendar; @@ -166,7 +167,9 @@ public class ToDate implements Function { return date; } else { try { - return javax.xml.bind.DatatypeConverter.parseDateTime(o1).getTime().toInstant().atOffset(ZoneOffset.of("Z")); + return javax.xml.bind.DatatypeConverter.parseDateTime(o1).getTime().toInstant() + .plusSeconds(ZonedDateTime.now().getOffset().getTotalSeconds()) + .atOffset(ZoneOffset.of("Z")); } catch (IllegalArgumentException e2) { return null; } diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToFromConversionTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToFromConversionTests.java index cb7f467c4..2fb4ab2d9 100644 --- a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToFromConversionTests.java +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToFromConversionTests.java @@ -49,6 +49,7 @@ import com.google.refine.expr.util.CalendarParserException; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; import com.google.refine.tests.RefineTest; +import com.google.refine.util.ParsingUtilities; /** @@ -161,10 +162,10 @@ public class ToFromConversionTests extends RefineTest { Assert.assertEquals(invoke("toDate", "01-六月-2013","zh","dd-MMM-yyyy"), CalendarParser.parseAsOffsetDateTime("2013-06-01")); //if invalid format/locale strings are passed, ignore them - Assert.assertEquals(invoke("toDate", "2012-03-01","XXX"), CalendarParser.parseAsOffsetDateTime("2012-03-01")); + Assert.assertEquals(invoke("toDate", "2012-03-01","XXX"), invoke("toDate", "2012-03-01")); // If a long, convert to string - Assert.assertEquals(invoke("toDate", (long) 2012), CalendarParser.parseAsOffsetDateTime("2012-01-01")); + Assert.assertEquals(invoke("toDate", (long) 2012), invoke("toDate", "2012-01-01")); // If already a date, leave it alone Assert.assertEquals(invoke("toDate", CalendarParser.parseAsOffsetDateTime("2012-03-01")),CalendarParser.parseAsOffsetDateTime("2012-03-01"));