--
---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
long now = 1460000000000L;//System.currentTimeMillis();
log.info("Driver version='{}', DB version='{}'", org.postgresql.Driver.getVersion(), jdbc.queryForObject("select version()", String.class));
jdbc.execute("create table dummy (ts timestamp not null, tswz timestamp with time zone not null)");
log.info("jvm-tz={}, pg-tz={}", TimeZone.getDefault().getID(), jdbc.queryForObject("show time zone", String.class));
log.info("src= {}", ts2s(new Timestamp(now)));
jdbc.update("insert into dummy (ts, tswz) values (?, ?)", new Timestamp(now), new Timestamp(now));
Map<String, Object> result1 = jdbc.queryForMap("select * from dummy limit 1");
log.info("ts= {}\ntswz={}", ts2s(result1.get("ts")), ts2s(result1.get("tswz")));
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); // this could be a different application accessing the DB
jdbc.execute("set time zone 'Europe/Berlin'");
log.info("jvm-tz={}, pg-tz={}", TimeZone.getDefault().getID(), jdbc.queryForObject("show time zone", String.class));
Map<String, Object> result2 = jdbc.queryForMap("select * from dummy limit 1");
log.info("ts= {}\ntswz={}", ts2s(result2.get("ts")), ts2s(result2.get("tswz")));
jdbc.execute("set time zone 'Europe/Dublin'");
log.info("jvm-tz={}, pg-tz={}", TimeZone.getDefault().getID(), jdbc.queryForObject("show time zone", String.class));
Map<String, Object> result3 = jdbc.queryForMap("select * from dummy limit 1");
log.info("ts= {}\ntswz={}", ts2s(result3.get("ts")), ts2s(result3.get("tswz")));
// Driver version='PostgreSQL 9.4.1208'
// DB version='PostgreSQL 9.5.2 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2, 64-bit'
//
// jvm-tz=Pacific/Auckland, pg-tz=Pacific/Auckland
// src= [millis=1460000000000 local=2016-04-07 15:33:20.0 utc=2016-04-07T03:33:20Z]
// ts= [millis=1460000000000 local=2016-04-07 15:33:20.0 utc=2016-04-07T03:33:20Z]
// tswz=[millis=1460000000000 local=2016-04-07 15:33:20.0 utc=2016-04-07T03:33:20Z]
//
// jvm-tz=America/Los_Angeles, pg-tz=Europe/Berlin
// ts= [millis=1460068400000 local=2016-04-07 15:33:20.0 utc=2016-04-07T22:33:20Z]
// tswz=[millis=1460000000000 local=2016-04-06 20:33:20.0 utc=2016-04-07T03:33:20Z]
//
// jvm-tz=America/Los_Angeles, pg-tz=Europe/Dublin
// ts= [millis=1460068400000 local=2016-04-07 15:33:20.0 utc=2016-04-07T22:33:20Z]
// tswz=[millis=1460000000000 local=2016-04-06 20:33:20.0 utc=2016-04-07T03:33:20Z]
postgres=# set time zone 'utc'; select * from dummy;
SET
ts | tswz
---------------------+------------------------
2016-04-07 15:33:20 | 2016-04-07 03:33:20+00
(1 row)
postgres=# set time zone 'Pacific/Auckland'; select * from dummy;
SET
ts | tswz
---------------------+------------------------
2016-04-07 15:33:20 | 2016-04-07 15:33:20+12
(1 row)
protected String ts2s(Object ts) {
return String.format("[millis=%d local=%s utc=%s]", ((Timestamp) ts).getTime(), ts, ((Timestamp) ts).toInstant());
}
I guess the 'set time zone xxx' isn't really necessary, I mainly put that in there to demonstrate that it doesn't affect the visible behaviour in this case. By default the JDBC driver (at least the 9.4) seems to set the JVM default time zone as the DB session time zone as well, but even when it's changed 'timestamp' fields don't get affected at all.
In terms of TimeZone.setDefault() during the test you need to be careful depending on which version of the driver you're using. 9.3 will cache the Calendar with the TZ internally, so the logic that transforms the string received from the DB into the millis value it puts into the java.sql.Timestamp doesn't see the changed zone. Which version are you using? Can you try leaving the values in the DB, and the running the 'fetch' in a separate JVM with a different default TZ?
I think for your 'with calendar' examples ts1/tswz1 you should also supply the same calendar to getTimestamp() in fetch()
You received this message because you are subscribed to a topic in the Google Groups "Ebean ORM" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ebean/OlHWFWImiXE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ebean+un...@googlegroups.com.