pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: spm@spamik.cz
To: pgsql-bugs@postgresql.org
Subject: BUG #7888: Small issue on wiki page Round time
Date: Sun, 17 Feb 2013 19:14:00 +0000
Message-ID: <E1U79gW-0003fN-8b@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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



view thread (2+ messages)  latest in thread

Message-ID: <E1U79gW-0003fN-8b@wrigleys.postgresql.org>
Permalink:  ../E1U79gW-0003fN-8b@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/E1U79gW-0003fN-8b@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: spm@spamik.cz
  Subject: Re: BUG #7888: Small issue on wiki page Round time
  In-Reply-To: <E1U79gW-0003fN-8b@wrigleys.postgresql.org>
  References: <E1U79gW-0003fN-8b@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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