Re: BUG #15388: time convert error when use AT TIME ZONE '+8' - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #15388: time convert error when use AT TIME ZONE '+8'
Date
Msg-id 20541.1537242305@sss.pgh.pa.us
Whole thread Raw
In response to BUG #15388: time convert error when use AT TIME ZONE '+8'  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #15388: time convert error when use AT TIME ZONE '+8'  ("Peter J. Holzer" <hjp-pgsql@hjp.at>)
List pgsql-bugs
=?utf-8?q?PG_Bug_reporting_form?= <noreply@postgresql.org> writes:
> 1. What did you do?
> SET TIME ZONE 'utc';
> SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE '+8';

> 2. What did you expect to see?
>         timezone
> ------------------------
>  2001-02-16 12:38:40+00

You're apparently confused about the sign of time zone offsets.
In a POSIX-style zone name, which is what you have there, plus
means west of Greenwich; so this is the right answer:

> 3. What did you see instead?
>         timezone
> ------------------------
>  2001-02-17 04:38:40+00

See

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

notably the comment that

   Another issue to keep in mind is that in POSIX time zone names,
   positive offsets are used for locations west of Greenwich. Everywhere
   else, PostgreSQL follows the ISO-8601 convention that positive timezone
   offsets are east of Greenwich.

If you want to use the ISO sign convention, you can do it with an
interval-type zone specification:

regression=# SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE '+8:00'::interval;
        timezone
------------------------
 2001-02-16 12:38:40+00
(1 row)

            regards, tom lane


pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #15387: explain analyze timing on bug?
Next
From: Amit Kapila
Date:
Subject: Re: log_destination reload/restart doesn't stop file creation