diff --git a/main/src/com/google/refine/util/ParsingUtilities.java b/main/src/com/google/refine/util/ParsingUtilities.java index 4de898685..a4f56e445 100644 --- a/main/src/com/google/refine/util/ParsingUtilities.java +++ b/main/src/com/google/refine/util/ParsingUtilities.java @@ -39,8 +39,10 @@ import java.io.InputStreamReader; import java.io.Reader; import java.io.UnsupportedEncodingException; import java.text.SimpleDateFormat; +import java.time.Instant; import java.time.LocalDateTime; import java.time.OffsetDateTime; +import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Properties; @@ -193,6 +195,11 @@ public class ParsingUtilities { } static public LocalDateTime stringToLocalDate(String s) { - return LocalDateTime.parse(s, DateTimeFormatter.ISO_LOCAL_DATE_TIME); + if (s.endsWith("Z")) { // UTC time + Instant instant = Instant.parse(s); + return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()); + } else { + return LocalDateTime.parse(s, DateTimeFormatter.ISO_LOCAL_DATE_TIME); + } } } diff --git a/main/tests/server/src/com/google/refine/tests/util/ParsingUtilitiesTests.java b/main/tests/server/src/com/google/refine/tests/util/ParsingUtilitiesTests.java index 87a649d86..91baccd76 100644 --- a/main/tests/server/src/com/google/refine/tests/util/ParsingUtilitiesTests.java +++ b/main/tests/server/src/com/google/refine/tests/util/ParsingUtilitiesTests.java @@ -35,7 +35,10 @@ package com.google.refine.tests.util; import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.lang3.text.StrSubstitutor; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.LoggerFactory; @@ -90,9 +93,6 @@ public class ParsingUtilitiesTests extends RefineTest { } @Test public void zonedDateTimeTest() { -// String d = "2017-07-18T20:26:28.582+03:00[Asia/Istanbul]"; -// DateTimeFormatter formatter = DateTimeFormatter.ISO_ZONED_DATE_TIME ; -// OffsetDateTime.parse(d, formatter); String d = "2017-12-01T14:53:36Z"; DateTimeFormatter formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME; OffsetDateTime.parse(d, formatter); @@ -107,4 +107,24 @@ public class ParsingUtilitiesTests extends RefineTest { Assert.assertEquals(zdtString, historyEntryDate); } + + @Test + public void parseProjectModifiedBeforeJDK8() { + String modified = "2014-01-15T21:46:25Z"; + Assert.assertNotEquals(ParsingUtilities.stringToLocalDate(modified).toString(), + modified); + } + + @Test + public void strSubstitutorTest() { + Map data = new HashMap(6); + + data.put("value", "1234"); + data.put("field_format", "String"); + + StrSubstitutor sub = new StrSubstitutor(data); + String message = "The value ${value} in row ${row_number} and column ${column_number} is not type ${field_type} and format ${field_format}"; + String result = sub.replace(message); + Assert.assertTrue(result.contains("1234")); + } }