Merge pull request #1388 from jackyq2015/issue/1386

Fix Issue #1386
This commit is contained in:
Jacky 2017-12-21 08:26:29 -05:00 committed by GitHub
commit fb3620b3d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 4 deletions

View File

@ -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);
}
}
}

View File

@ -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<String, String> data = new HashMap<String, String>(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"));
}
}