pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #7888: Small issue on wiki page Round time
2+ messages / 2 participants
[nested] [flat]

* BUG #7888: Small issue on wiki page Round time
@ 2013-02-17 19:14  spm@spamik.cz
  0 siblings, 1 reply; 2+ messages in thread

From: spm@spamik.cz @ 2013-02-17 19:14 UTC (permalink / raw)
  To: pgsql-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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #7888: Small issue on wiki page Round time
@ 2013-02-18 14:26  Bruce Momjian <bruce@momjian.us>
  parent: spm@spamik.cz
  0 siblings, 0 replies; 2+ messages in thread

From: Bruce Momjian @ 2013-02-18 14:26 UTC (permalink / raw)
  To: spm@spamik.cz; +Cc: pgsql-bugs


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  <bruce@momjian.us>        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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2013-02-18 14:26 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-02-17 19:14 BUG #7888: Small issue on wiki page Round time spm@spamik.cz
2013-02-18 14:26 ` Bruce Momjian <bruce@momjian.us>

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