Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YnGPJ-0004C3-U7 for pgsql-bugs@arkaria.postgresql.org; Wed, 29 Apr 2015 01:03:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YnGPJ-0006VE-Cz for pgsql-bugs@arkaria.postgresql.org; Wed, 29 Apr 2015 01:03:21 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YnGPH-0006SQ-NK for pgsql-bugs@postgresql.org; Wed, 29 Apr 2015 01:03:19 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1YnGPE-0007te-Gz for pgsql-bugs@postgresql.org; Wed, 29 Apr 2015 01:03:17 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1YnGPD-0007nd-Ra; Tue, 28 Apr 2015 21:03:15 -0400 Date: Tue, 28 Apr 2015 21:03:15 -0400 From: Bruce Momjian To: david.pozsar@gmail.com Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #12754: The 'OF' template pattern of to_char() print incorrect results with negative offsets with minutes Message-ID: <20150429010315.GH31727@momjian.us> References: <20150210095658.18792.72359@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ftEhullJWpWg/VHq" Content-Disposition: inline In-Reply-To: <20150210095658.18792.72359@wrigleys.postgresql.org> User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --ftEhullJWpWg/VHq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Feb 10, 2015 at 09:56:58AM +0000, david.pozsar@gmail.com wrote: > The following bug has been logged on the website: > > Bug reference: 12754 > Logged by: David Pozsar > Email address: david.pozsar@gmail.com > PostgreSQL version: 9.4.0 > Operating system: Windows 7 > Description: > > If the current time-zone has minutes and is negative, to_char('OF') prints a > negative sign before the minute part too. > > Code, to reproduce: > > set time zone interval '-02:30'; > -- or: set timezone to -2.5; > select ts::text, to_char(ts, 'YYYY-MM-DD HH24:MI:SSOF') > from (values (timestamptz '2015-02-10 07:05:15+00')) v(ts); > > Output: > > ts | to_char > ---------------------------+---------------------------- > 2015-02-10 04:35:15-02:30 | 2015-02-10 04:35:15-02:-30 > > Expected output: > > ts | to_char > ---------------------------+--------------------------- > 2015-02-10 04:35:15-02:30 | 2015-02-10 04:35:15-02:30 Attached patch applied. Thanks for the clear report. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + Everyone has their own god. + --ftEhullJWpWg/VHq Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="to_char.diff" diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c new file mode 100644 index 40a353f..576db95 *** a/src/backend/utils/adt/formatting.c --- b/src/backend/utils/adt/formatting.c *************** DCH_to_char(FormatNode *node, bool is_in *** 2507,2513 **** s += strlen(s); if (tm->tm_gmtoff % SECS_PER_HOUR != 0) { ! sprintf(s, ":%02ld", (tm->tm_gmtoff % SECS_PER_HOUR) / SECS_PER_MINUTE); s += strlen(s); } break; --- 2507,2513 ---- s += strlen(s); if (tm->tm_gmtoff % SECS_PER_HOUR != 0) { ! sprintf(s, ":%02ld", abs(tm->tm_gmtoff % SECS_PER_HOUR) / SECS_PER_MINUTE); s += strlen(s); } break; --ftEhullJWpWg/VHq Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --ftEhullJWpWg/VHq--