Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U7RgP-0001sa-8z for pgsql-bugs@arkaria.postgresql.org; Mon, 18 Feb 2013 14:27:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1U7RgO-00063M-2W for pgsql-bugs@arkaria.postgresql.org; Mon, 18 Feb 2013 14:27:04 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U7RgN-00063H-Cw for pgsql-bugs@postgresql.org; Mon, 18 Feb 2013 14:27:03 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U7RgG-0007Vt-R4 for pgsql-bugs@postgresql.org; Mon, 18 Feb 2013 14:27:02 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1U7RgE-0004Gt-54; Mon, 18 Feb 2013 09:26:54 -0500 Date: Mon, 18 Feb 2013 09:26:54 -0500 From: Bruce Momjian To: spm@spamik.cz Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #7888: Small issue on wiki page Round time Message-ID: <20130218142654.GM12030@momjian.us> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -2.5 (--) 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 It is a wiki, so you can easily get an account and make the change yourself. Thanks. --------------------------------------------------------------------------- On Sun, Feb 17, 2013 at 07:14:00PM +0000, spm@spamik.cz wrote: > The following bug has been logged on the website: > > Bug reference: 7888 > Logged by: Jan Krajdl > Email address: spm@spamik.cz > PostgreSQL version: Unsupported/Unknown > Operating system: all > Description: > > Hi, > > I have found small issue on this wiki page: > http://wiki.postgresql.org/wiki/Round_time > > There is mistake in "alternative approach" function - select > '1970-01-01'::timestamptz results in timestamp '1970-01-01 00:00:00' with > local timezone. But function is using it as a start of epoch which was same > time but in timezone GMT. If you use this function and you have postgres > server in non GMT timezone, rounded results are in GMT timezone but they > have timezone information about local timezone. > > I'm quite noob with postgres but I tried to fix it and it looks that this > code: > > CREATE FUNCTION date_round(base_date timestamptz, round_interval INTERVAL) > RETURNS timestamptz AS $BODY$ > SELECT TIMESTAMP WITH TIME ZONE 'epoch' + (EXTRACT(epoch FROM $1)::INTEGER + > EXTRACT(epoch FROM $2)::INTEGER / 2) > / EXTRACT(epoch FROM $2)::INTEGER * EXTRACT(epoch FROM > $2)::INTEGER * INTERVAL '1 second'; > $BODY$ LANGUAGE SQL STABLE; > > is doing it better - returned time looks correct. So if you want you can > update this page. > > Regards, > > -- > Jan Krajdl > > > > -- > Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-bugs -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. + -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs