Skip to content

Commit

Permalink
Merge pull request #3 from Bit-Quill/timestamp-issue
Browse files Browse the repository at this point in the history
Fix for ADDDATE and SUBDATE with resulting 00:00:00 being unexpectedly null
  • Loading branch information
guiangumpac authored Nov 18, 2021
2 parents dd357bc + a4d2c0c commit 5a90ca7
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Map;
Expand Down Expand Up @@ -78,13 +79,17 @@ else if (value.charAt(23) == '+' || value.charAt(23) == '-') {
}
}

if (calendar == null) {
return Timestamp.valueOf(value);
final Timestamp ts;
if (value.length() < 11) {
ts = Timestamp.valueOf(LocalDate.parse(value).atStartOfDay());
} else {
Timestamp ts = Timestamp.valueOf(value);
return localDateTimeToTimestamp(ts.toLocalDateTime(), calendar);
ts = Timestamp.valueOf(value);
}

if (calendar == null) {
return ts;
}
return localDateTimeToTimestamp(ts.toLocalDateTime(), calendar);
} catch (IllegalArgumentException iae) {
throw stringConversionException(value, iae);
}
Expand Down

0 comments on commit 5a90ca7

Please sign in to comment.