Github user jiang-wu commented on a diff in the pull request:
https://github.com/apache/drill/pull/1247#discussion_r185358628
--- Diff: exec/vector/src/main/java/org/apache/drill/exec/expr/fn/impl/DateUtility.java
---
@@ -639,29 +648,95 @@ public static String getTimeZone(int index) {
return timezoneList[index];
}
+ /**
+ * Parse given string into a LocalDate
+ */
+ public static LocalDate parseLocalDate(final String value) {
+ return LocalDate.parse(value, formatDate);
+ }
+
+ /**
+ * Parse given string into a LocalTime
+ */
+ public static LocalTime parseLocalTime(final String value) {
+ return LocalTime.parse(value, formatTime);
+ }
+
+ /**
+ * Parse the given string into a LocalDateTime.
+ */
+ public static LocalDateTime parseLocalDateTime(final String value) {
+ return LocalDateTime.parse(value, formatTimeStamp);
+ }
+
// Returns the date time formatter used to parse date strings
public static DateTimeFormatter getDateTimeFormatter() {
if (dateTimeTZFormat == null) {
- DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");
- DateTimeParser optionalTime = DateTimeFormat.forPattern(" HH:mm:ss").getParser();
- DateTimeParser optionalSec = DateTimeFormat.forPattern(".SSS").getParser();
- DateTimeParser optionalZone = DateTimeFormat.forPattern(" ZZZ").getParser();
+ DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+ DateTimeFormatter optionalTime = DateTimeFormatter.ofPattern(" HH:mm:ss");
+ DateTimeFormatter optionalSec = DateTimeFormatter.ofPattern(".SSS");
+ DateTimeFormatter optionalZone = DateTimeFormatter.ofPattern(" ZZZ");
- dateTimeTZFormat = new DateTimeFormatterBuilder().append(dateFormatter).appendOptional(optionalTime).appendOptional(optionalSec).appendOptional(optionalZone).toFormatter();
+ dateTimeTZFormat = new DateTimeFormatterBuilder().parseLenient()
+ .append(dateFormatter)
+ .appendOptional(optionalTime)
+ .appendOptional(optionalSec)
+ .appendOptional(optionalZone)
+ .toFormatter();
}
return dateTimeTZFormat;
}
+ /**
--- End diff --
parseBest is used only by JUnit tests when the string value is not very strict. Example,
"2018-1-1 12:1" instead of "2018-01-01 12:01". This method is more lenient and tolerating
missing parts when parsing a date time.
---
|