commit
fb3620b3d9
@ -39,8 +39,10 @@ import java.io.InputStreamReader;
|
|||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.Instant;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@ -193,6 +195,11 @@ public class ParsingUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public LocalDateTime stringToLocalDate(String s) {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,10 @@ package com.google.refine.tests.util;
|
|||||||
|
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
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.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -90,9 +93,6 @@ public class ParsingUtilitiesTests extends RefineTest {
|
|||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void zonedDateTimeTest() {
|
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";
|
String d = "2017-12-01T14:53:36Z";
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
DateTimeFormatter formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
||||||
OffsetDateTime.parse(d, formatter);
|
OffsetDateTime.parse(d, formatter);
|
||||||
@ -107,4 +107,24 @@ public class ParsingUtilitiesTests extends RefineTest {
|
|||||||
Assert.assertEquals(zdtString, historyEntryDate);
|
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"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user