Skip to content

Commit

Permalink
0004272: FormatUtils parseTimestampWithTimezone interprets fractional
Browse files Browse the repository at this point in the history
seconds incorrectly
  • Loading branch information
philipmarzullo64 committed Feb 4, 2020
1 parent 56c1d96 commit 946eeeb
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions symmetric-util/src/main/java/org/jumpmind/util/FormatUtils.java
Expand Up @@ -433,6 +433,19 @@ public static Timestamp parseTimestampWithTimezone(String str) {

public static Timestamp parseTimestampWithTimezone(String str, String[] parsePatterns) {
Timestamp ret = null;
// Need to make sure that the fraction seconds has nine digits,
// because of a parse bug in Java version 8
String dateTime = str.substring(0, str.indexOf("."));
String fractionSeconds = str.substring(str.indexOf(".")+1, str.lastIndexOf(" "));
String timeZone = str.substring(str.lastIndexOf(" ")+1);
if(dateTime == null || dateTime.length() == 0 ||
fractionSeconds == null || fractionSeconds.length() == 0 ||
timeZone == null || timeZone.length() == 0)
{
throw new ParseException("Unable to parse the date: " + str);
}
fractionSeconds = StringUtils.rightPad(fractionSeconds, 9, '0');
str = dateTime + "." + fractionSeconds + " " + timeZone;
for(int i = 0; i < parsePatterns.length; i++) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(parsePatterns[i]);
ret = null;
Expand Down

0 comments on commit 946eeeb

Please sign in to comment.