pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Startup parameters timezone conversion
8+ messages / 5 participants
[nested] [flat]

* Startup parameters timezone conversion
@ 2022-01-19 12:11 Leonid Vygovskiy <Leonid.Vygovskiy@gmail.com>
  2022-01-19 14:01 ` Re: Startup parameters timezone conversion Dave Cramer <davecramer@postgres.rocks>
  2022-01-19 14:54 ` Re: Startup parameters timezone conversion Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 8+ messages in thread

From: Leonid Vygovskiy @ 2022-01-19 12:11 UTC (permalink / raw)
  To: pgsql-jdbc@lists.postgresql.org

Hi all!

I study how to work with the timezone in JDBC driver and found the code
which I don't understand.
This is implementation of the method
ConnectionFactoryImpl.createPostgresTimeZone() which has the comment:"
Convert Java time zone to postgres time zone. All others stay the same
except that GMT+n  changes to GMT-nn and vise versa."

I'm confused with that changing. Can anybody talk about the reasons and
motives of this behavior?

BR, Leonid Vygovskiy

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Startup parameters timezone conversion
  2022-01-19 12:11 Startup parameters timezone conversion Leonid Vygovskiy <Leonid.Vygovskiy@gmail.com>
@ 2022-01-19 14:01 ` Dave Cramer <davecramer@postgres.rocks>
  2022-01-19 14:41   ` Re: Startup parameters timezone conversion Thomas Kellerer <shammat@gmx.net>
  1 sibling, 1 reply; 8+ messages in thread

From: Dave Cramer @ 2022-01-19 14:01 UTC (permalink / raw)
  To: Leonid Vygovskiy <Leonid.Vygovskiy@gmail.com>; +Cc: pgsql-jdbc@lists.postgresql.org

I have to admit to being unable to explain this as well.


Dave Cramer
www.postgres.rocks


On Wed, 19 Jan 2022 at 08:22, Leonid Vygovskiy <Leonid.Vygovskiy@gmail.com>
wrote:

> Hi all!
>
> I study how to work with the timezone in JDBC driver and found the code
> which I don't understand.
> This is implementation of the method
> ConnectionFactoryImpl.createPostgresTimeZone() which has the comment:"
> Convert Java time zone to postgres time zone. All others stay the same
> except that GMT+n  changes to GMT-nn and vise versa."
>
> I'm confused with that changing. Can anybody talk about the reasons and
> motives of this behavior?
>
> BR, Leonid Vygovskiy
>

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Startup parameters timezone conversion
  2022-01-19 12:11 Startup parameters timezone conversion Leonid Vygovskiy <Leonid.Vygovskiy@gmail.com>
  2022-01-19 14:01 ` Re: Startup parameters timezone conversion Dave Cramer <davecramer@postgres.rocks>
@ 2022-01-19 14:41   ` Thomas Kellerer <shammat@gmx.net>
  2022-01-19 14:53     ` Re: Startup parameters timezone conversion David G. Johnston <david.g.johnston@gmail.com>
  2022-01-19 15:08     ` Re: Startup parameters timezone conversion Dave Cramer <davecramer@postgres.rocks>
  0 siblings, 2 replies; 8+ messages in thread

From: Thomas Kellerer @ 2022-01-19 14:41 UTC (permalink / raw)
  To: pgsql-jdbc@lists.postgresql.org

Could this be related to Posix time zones?

https://www.postgresql.org/docs/current/datetime-posix-timezone-specs.html

> the positive sign is used for zones west of Greenwich. (Note that this is the opposite of the ISO-8601 sign convention used elsewhere in PostgreSQL

Thomas

Dave Cramer schrieb am 19.01.2022 um 15:01:
> I have to admit to being unable to explain this as well.
>
>
> Dave Cramer
> www.postgres.rocks
>
>
> On Wed, 19 Jan 2022 at 08:22, Leonid Vygovskiy <Leonid.Vygovskiy@gmail.com <mailto:Leonid.Vygovskiy@gmail.com>> wrote:
>
>     Hi all!
>
>     I study how to work with the timezone in JDBC driver and found the code which I don't understand.
>     This is implementation of the method ConnectionFactoryImpl.createPostgresTimeZone() which has the comment:" Convert Java time zone to postgres time zone. All others stay the same except that GMT+n  changes to GMT-nn and vise versa."
>
>     I'm confused with that changing. Can anybody talk about the reasons and motives of this behavior?
>
>     BR, Leonid Vygovskiy
>





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Startup parameters timezone conversion
  2022-01-19 12:11 Startup parameters timezone conversion Leonid Vygovskiy <Leonid.Vygovskiy@gmail.com>
  2022-01-19 14:01 ` Re: Startup parameters timezone conversion Dave Cramer <davecramer@postgres.rocks>
  2022-01-19 14:41   ` Re: Startup parameters timezone conversion Thomas Kellerer <shammat@gmx.net>
@ 2022-01-19 14:53     ` David G. Johnston <david.g.johnston@gmail.com>
  2022-01-19 15:07       ` Re: Startup parameters timezone conversion Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 8+ messages in thread

From: David G. Johnston @ 2022-01-19 14:53 UTC (permalink / raw)
  To: Thomas Kellerer <shammat@gmx.net>; +Cc: pgsql-jdbc@lists.postgresql.org <pgsql-jdbc@lists.postgresql.org>

On Wednesday, January 19, 2022, Thomas Kellerer <shammat@gmx.net> wrote:

> Could this be related to Posix time zones?
>
> https://www.postgresql.org/docs/current/datetime-posix-timezone-specs.html
>
> > the positive sign is used for zones west of Greenwich. (Note that this
> is the opposite of the ISO-8601 sign convention used elsewhere in PostgreSQL
>

Indeed I presume it is.  I wonder whether a carefully chosen timezone
specification on the server would cause this to break since the server can
be made to report the offset using either convention and so at least for
some timezone specifications the flipping of the sign would not be required…

David J.

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Startup parameters timezone conversion
  2022-01-19 12:11 Startup parameters timezone conversion Leonid Vygovskiy <Leonid.Vygovskiy@gmail.com>
  2022-01-19 14:01 ` Re: Startup parameters timezone conversion Dave Cramer <davecramer@postgres.rocks>
  2022-01-19 14:41   ` Re: Startup parameters timezone conversion Thomas Kellerer <shammat@gmx.net>
  2022-01-19 14:53     ` Re: Startup parameters timezone conversion David G. Johnston <david.g.johnston@gmail.com>
@ 2022-01-19 15:07       ` Tom Lane <tgl@sss.pgh.pa.us>
  2022-01-19 15:20         ` Re: Startup parameters timezone conversion Dave Cramer <davecramer@postgres.rocks>
  0 siblings, 1 reply; 8+ messages in thread

From: Tom Lane @ 2022-01-19 15:07 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Thomas Kellerer <shammat@gmx.net>; pgsql-jdbc@lists.postgresql.org <pgsql-jdbc@lists.postgresql.org>

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> Indeed I presume it is.  I wonder whether a carefully chosen timezone
> specification on the server would cause this to break since the server can
> be made to report the offset using either convention and so at least for
> some timezone specifications the flipping of the sign would not be required…

AFAIK, "reporting the offset" is always done with the ISO convention.
It's only when trying to interpret a time zone specification that
we consider the POSIX convention (and that's mostly because the
underlying tzdb code does so).  This does lead to fun stuff like

postgres=# set timezone = 'GMT+2';    -- read as POSIX zone spec
SET
postgres=# select now();
              now              
-------------------------------
 2022-01-19 13:03:36.000152-02        -- report as ISO
(1 row)

postgres=# set timezone = '+2';       -- read as numeric ISO offset
SET
postgres=# select now();
              now              
-------------------------------
 2022-01-19 17:03:41.722767+02        -- report as ISO
(1 row)

IMO, all these cases are best-avoided legacy conventions.
In practice you should set the timezone using the tzdb zone name
for where you live, e.g. America/New_York.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Startup parameters timezone conversion
  2022-01-19 12:11 Startup parameters timezone conversion Leonid Vygovskiy <Leonid.Vygovskiy@gmail.com>
  2022-01-19 14:01 ` Re: Startup parameters timezone conversion Dave Cramer <davecramer@postgres.rocks>
  2022-01-19 14:41   ` Re: Startup parameters timezone conversion Thomas Kellerer <shammat@gmx.net>
  2022-01-19 14:53     ` Re: Startup parameters timezone conversion David G. Johnston <david.g.johnston@gmail.com>
  2022-01-19 15:07       ` Re: Startup parameters timezone conversion Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-01-19 15:20         ` Dave Cramer <davecramer@postgres.rocks>
  0 siblings, 0 replies; 8+ messages in thread

From: Dave Cramer @ 2022-01-19 15:20 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: David G. Johnston <david.g.johnston@gmail.com>; Thomas Kellerer <shammat@gmx.net>; pgsql-jdbc@lists.postgresql.org <pgsql-jdbc@lists.postgresql.org>

On Wed, 19 Jan 2022 at 10:17, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> "David G. Johnston" <david.g.johnston@gmail.com> writes:
> > Indeed I presume it is.  I wonder whether a carefully chosen timezone
> > specification on the server would cause this to break since the server
> can
> > be made to report the offset using either convention and so at least for
> > some timezone specifications the flipping of the sign would not be
> required…
>
> AFAIK, "reporting the offset" is always done with the ISO convention.
> It's only when trying to interpret a time zone specification that
> we consider the POSIX convention (and that's mostly because the
> underlying tzdb code does so).  This does lead to fun stuff like
>
> postgres=# set timezone = 'GMT+2';    -- read as POSIX zone spec
> SET
> postgres=# select now();
>               now
> -------------------------------
>  2022-01-19 13:03:36.000152-02        -- report as ISO
> (1 row)
>
> postgres=# set timezone = '+2';       -- read as numeric ISO offset
> SET
> postgres=# select now();
>               now
> -------------------------------
>  2022-01-19 17:03:41.722767+02        -- report as ISO
> (1 row)
>
> IMO, all these cases are best-avoided legacy conventions.
> In practice you should set the timezone using the tzdb zone name
> for where you live, e.g. America/New_York.
>
>                         regards, tom lane
>

Thanks Tom

We don't really deal with +2 without GMT in java so this isn't an issue.
The code really only switches POSIX to ISO

I'll add a comment to the code.

Man I love API's

Dave

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Startup parameters timezone conversion
  2022-01-19 12:11 Startup parameters timezone conversion Leonid Vygovskiy <Leonid.Vygovskiy@gmail.com>
  2022-01-19 14:01 ` Re: Startup parameters timezone conversion Dave Cramer <davecramer@postgres.rocks>
  2022-01-19 14:41   ` Re: Startup parameters timezone conversion Thomas Kellerer <shammat@gmx.net>
@ 2022-01-19 15:08     ` Dave Cramer <davecramer@postgres.rocks>
  1 sibling, 0 replies; 8+ messages in thread

From: Dave Cramer @ 2022-01-19 15:08 UTC (permalink / raw)
  To: Thomas Kellerer <shammat@gmx.net>; +Cc: pgsql-jdbc@lists.postgresql.org

On Wed, 19 Jan 2022 at 09:42, Thomas Kellerer <shammat@gmx.net> wrote:

> Could this be related to Posix time zones?
>
> https://www.postgresql.org/docs/current/datetime-posix-timezone-specs.html
>
> > the positive sign is used for zones west of Greenwich. (Note that this
> is the opposite of the ISO-8601 sign convention used elsewhere in PostgreSQL
>
> Thomas
>

Yes this is the case

test=# set timezone to 'GMT-5';
SET
test=# select now();
              now
-------------------------------
 2022-01-19 20:05:25.515391+05
(1 row)

test=# set timezone to 'GMT+5';
SET
test=# select now();
              now
-------------------------------
 2022-01-19 10:05:52.054867-05
(1 row)


>

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Startup parameters timezone conversion
  2022-01-19 12:11 Startup parameters timezone conversion Leonid Vygovskiy <Leonid.Vygovskiy@gmail.com>
@ 2022-01-19 14:54 ` Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 0 replies; 8+ messages in thread

From: Tom Lane @ 2022-01-19 14:54 UTC (permalink / raw)
  To: Leonid Vygovskiy <Leonid.Vygovskiy@gmail.com>; +Cc: pgsql-jdbc@lists.postgresql.org

Leonid Vygovskiy <Leonid.Vygovskiy@gmail.com> writes:
> I study how to work with the timezone in JDBC driver and found the code
> which I don't understand.
> This is implementation of the method
> ConnectionFactoryImpl.createPostgresTimeZone() which has the comment:"
> Convert Java time zone to postgres time zone. All others stay the same
> except that GMT+n  changes to GMT-nn and vise versa."
> I'm confused with that changing. Can anybody talk about the reasons and
> motives of this behavior?

I'm guessing that Java thinks the time zone name "GMT+2" means 2 hours
east of Greenwich (ISO-8601 sign convention).  Postgres thinks it means
2 hours west of Greenwich (POSIX sign convention).  See

https://www.postgresql.org/docs/current/datatype-datetime.html#DATATYPE-TIMEZONES

https://www.postgresql.org/docs/current/datetime-posix-timezone-specs.html

The great thing about standards is there are so many to choose from ;-)

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2022-01-19 15:20 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-01-19 12:11 Startup parameters timezone conversion Leonid Vygovskiy <Leonid.Vygovskiy@gmail.com>
2022-01-19 14:01 ` Dave Cramer <davecramer@postgres.rocks>
2022-01-19 14:41   ` Thomas Kellerer <shammat@gmx.net>
2022-01-19 14:53     ` David G. Johnston <david.g.johnston@gmail.com>
2022-01-19 15:07       ` Tom Lane <tgl@sss.pgh.pa.us>
2022-01-19 15:20         ` Dave Cramer <davecramer@postgres.rocks>
2022-01-19 15:08     ` Dave Cramer <davecramer@postgres.rocks>
2022-01-19 14:54 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox