This commit is contained in:
jackyq2015 2017-12-19 12:54:26 -05:00
parent eeb8ade5c0
commit 81043e58e2
2 changed files with 28 additions and 2 deletions

View File

@ -38,9 +38,10 @@ import java.io.InputStream;
import java.io.InputStreamReader; 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.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 +194,10 @@ 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);
} }
} }

View File

@ -107,4 +107,25 @@ 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);
System.out.println("XXXXXXXX:" + result);
Assert.assertTrue(result.contains("1234"));
}
} }