Skip to content

Commit 5a90ca7

Browse files
author
guiangumpac
authored
Merge pull request #3 from Bit-Quill/timestamp-issue
Fix for ADDDATE and SUBDATE with resulting 00:00:00 being unexpectedly null
2 parents dd357bc + a4d2c0c commit 5a90ca7

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

sql-jdbc/src/main/java/org/opensearch/jdbc/types/TimestampType.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import java.sql.SQLException;
1010
import java.sql.Timestamp;
11+
import java.time.LocalDate;
1112
import java.time.LocalDateTime;
1213
import java.util.Calendar;
1314
import java.util.Map;
@@ -78,13 +79,17 @@ else if (value.charAt(23) == '+' || value.charAt(23) == '-') {
7879
}
7980
}
8081

81-
if (calendar == null) {
82-
return Timestamp.valueOf(value);
82+
final Timestamp ts;
83+
if (value.length() < 11) {
84+
ts = Timestamp.valueOf(LocalDate.parse(value).atStartOfDay());
8385
} else {
84-
Timestamp ts = Timestamp.valueOf(value);
85-
return localDateTimeToTimestamp(ts.toLocalDateTime(), calendar);
86+
ts = Timestamp.valueOf(value);
8687
}
8788

89+
if (calendar == null) {
90+
return ts;
91+
}
92+
return localDateTimeToTimestamp(ts.toLocalDateTime(), calendar);
8893
} catch (IllegalArgumentException iae) {
8994
throw stringConversionException(value, iae);
9095
}

0 commit comments

Comments
 (0)