Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with Row.getTimestamp() and time zones #45

Open
RyanHoldren opened this issue Jun 1, 2017 · 0 comments
Open

Problems with Row.getTimestamp() and time zones #45

RyanHoldren opened this issue Jun 1, 2017 · 0 comments
Assignees
Labels

Comments

@RyanHoldren
Copy link

I am having an issue with getTimestamp() and time zones. The following test fails because the actual result is offset to my local time. Prefixing the SQL query with SET TIME ZONE 'UTC' has no effect.

package com.github.ryanholdren.example;

import com.github.pgasync.ConnectionPool;
import com.github.pgasync.ConnectionPoolBuilder;
import com.opentable.db.postgres.embedded.EmbeddedPostgres;
import static com.opentable.db.postgres.embedded.EmbeddedPostgres.start;
import java.io.IOException;
import java.time.Instant;
import static java.time.Instant.parse;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.postgresql.ds.PGSimpleDataSource;

public class TimeZoneTest {

	private static final String SQL = "SELECT TIMESTAMP WITH TIME ZONE '2004-10-19T10:23:54Z' AS output;";
	private static final Instant EXPECTED = parse("2004-10-19T10:23:54Z");

	@Test
	public void test() throws IOException {
		try (final EmbeddedPostgres postgres = start()) {
			final PGSimpleDataSource database = (PGSimpleDataSource) postgres.getPostgresDatabase();
			final ConnectionPool pool = new ConnectionPoolBuilder()
				.hostname("localhost")
				.port(postgres.getPort())
				.database(database.getDatabaseName())
				.username(database.getUser())
				.password(database.getPassword())
				.build();
			final Instant actual = pool.queryRows(SQL).map(row -> {
				return row.getTimestamp(0).toInstant();
			}).toBlocking().first();
			assertEquals(EXPECTED, actual);
		}
	}

}

Here is the Maven project: TimeZoneTest.zip

@alaisi alaisi self-assigned this Jun 2, 2017
@alaisi alaisi added the bug label Jun 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants