Skip to content
This repository has been archived by the owner on Mar 31, 2021. It is now read-only.

Can not parse 2020-03-23T09:28:48+00:00 as a Timestamp #60

Closed
sunnyfun888 opened this issue Mar 12, 2020 · 2 comments
Closed

Can not parse 2020-03-23T09:28:48+00:00 as a Timestamp #60

sunnyfun888 opened this issue Mar 12, 2020 · 2 comments

Comments

@sunnyfun888
Copy link

sunnyfun888 commented Mar 12, 2020

The format of Timestamp is different in our elasticSearch, which we got is like
2020-03-23T09:28:48+00:00

I changed the source code of jdbc/types/TimestampType.java
from

        // Timestamp.valueOf() does not like timezone information
        if (value.length() > 23) {
            if (value.length() == 24 && value.charAt(23) == 'Z') {
                value = value.substring(0, 23);
            }
            else if (value.charAt(23) == '+' || value.charAt(23) == '-') {
                // 'calendar' parameter takes precedence
                if (calendar == null) {
                    calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT" + value.substring(23)));
                }
                value = value.substring(0, 23);
            }
        }

to

        // Timestamp.valueOf() does not like timezone information
        if (value.length() > 23) {
            if (value.length() == 24 && value.charAt(23) == 'Z') {
                value = value.substring(0, 23);
            } else {
				int delimiterIndex = value.length() - 6;
				if (value.charAt(delimiterIndex) == '+'
					  || value.charAt(delimiterIndex) == '-') {
				    // 'calendar' parameter takes precedence
				    if (calendar == null) {
				        calendar = Calendar.getInstance(
				        		TimeZone.getTimeZone("GMT" + value.substring(delimiterIndex)));
				    }
				    value = value.substring(0, delimiterIndex);
				}
			}
        }

It seems the compatibility is better.

@dai-chen
Copy link
Contributor

@sunnyfun888 Thanks for reporting! Will look into the issue.

anandshah123 added a commit to anandshah123/sql-jdbc that referenced this issue Apr 15, 2020
dai-chen pushed a commit that referenced this issue Apr 20, 2020
* #60 Use default holdability for prepareStatement + Tests

* Polish

Co-authored-by: Anand Shah <annshah@amazon.lu>
@anirudha
Copy link

please confirm if this works and re-open as necessary.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants