Re: BUG #15388: time convert error when use AT TIME ZONE '+8'

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: huhao0715(at)gmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #15388: time convert error when use AT TIME ZONE '+8'
Date: 2018-09-18 03:45:05
Message-ID: 20541.1537242305@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

=?utf-8?q?PG_Bug_reporting_form?= <noreply(at)postgresql(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Amit Kapila 2018-09-18 08:43:18 Re: log_destination reload/restart doesn't stop file creation
Previous Message Tom Lane 2018-09-18 03:27:03 Re: BUG #15387: explain analyze timing on bug?