pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedPossible bug in PGInterval class
4+ messages / 3 participants
[nested] [flat]
* Possible bug in PGInterval class
@ 2009-08-31 19:34 Ľubomír Varga <luvar@plaintext.sk>
2009-09-02 00:01 ` Re: Possible bug in PGInterval class Kris Jurka <books@ejurka.com>
0 siblings, 1 reply; 4+ messages in thread
From: Ľubomír Varga @ 2009-08-31 19:34 UTC (permalink / raw)
To: pgsql-jdbc
Hi.
I have noticed imho bad behaviour of add methods for PGInterval class.
(org.postgresql.util.PGInterval)
First is unlogical adding sum to parameter and not to object on which is
method invoked. (this is also writen in javadoc, so I accept it)
Second, critical for me, is to not using modulo in addition. So if you add 55
minutes to 55 minutes, you get 110 minutes instead of 1 hour and 50 minutes.
Is this bug or feature? Should I use to postprocessing of sql query result
some other date classes? (joda time, or java date class...)
Thanks for answer.
PS: If it is not bug, please add some description to javadoc also to this
behaviour.
I am using 8.4-701 build and source...
--
Odborník na všetko je zlý odborník. Ja sa snažím byť výnimkou potvrdzujúcou
pravidlo.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Possible bug in PGInterval class
2009-08-31 19:34 Possible bug in PGInterval class Ľubomír Varga <luvar@plaintext.sk>
@ 2009-09-02 00:01 ` Kris Jurka <books@ejurka.com>
2009-09-02 00:03 ` Re: Possible bug in PGInterval class Oliver Jowett <oliver@opencloud.com>
2009-09-02 19:01 ` Re: Possible bug in PGInterval class Ľubomír Varga <luvar@plaintext.sk>
0 siblings, 2 replies; 4+ messages in thread
From: Kris Jurka @ 2009-09-02 00:01 UTC (permalink / raw)
To: Ľubomír Varga <luvar@plaintext.sk>; +Cc: pgsql-jdbc
On Mon, 31 Aug 2009, ?ubom?r Varga wrote:
> I have noticed imho bad behaviour of add methods for PGInterval class.
> (org.postgresql.util.PGInterval)
>
> First is unlogical adding sum to parameter and not to object on which is
> method invoked. (this is also writen in javadoc, so I accept it)
This is to be similar to the add(Date) and add(Calendar) functions. For
them you wan't to add the interval to the passed object.
> Second, critical for me, is to not using modulo in addition. So if you
> add 55 minutes to 55 minutes, you get 110 minutes instead of 1 hour and
> 50 minutes.
For minutes and hours, it would be OK, but when rolling hours into days or
days into months, context is needed to know if you are near a daylight
saving time change or how many days are in the month. For this reason we
don't manipulate the values and leave them as is.
Kris Jurka
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Possible bug in PGInterval class
2009-08-31 19:34 Possible bug in PGInterval class Ľubomír Varga <luvar@plaintext.sk>
2009-09-02 00:01 ` Re: Possible bug in PGInterval class Kris Jurka <books@ejurka.com>
@ 2009-09-02 00:03 ` Oliver Jowett <oliver@opencloud.com>
1 sibling, 0 replies; 4+ messages in thread
From: Oliver Jowett @ 2009-09-02 00:03 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: L(ubomír Varga <luvar@plaintext.sk>; pgsql-jdbc
Kris Jurka wrote:
>
>
> On Mon, 31 Aug 2009, ?ubom?r Varga wrote:
>> First is unlogical adding sum to parameter and not to object on which is
>> method invoked. (this is also writen in javadoc, so I accept it)
>
> This is to be similar to the add(Date) and add(Calendar) functions. For
> them you wan't to add the interval to the passed object.
Maybe rename them to addTo() ?
-O
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Possible bug in PGInterval class
2009-08-31 19:34 Possible bug in PGInterval class Ľubomír Varga <luvar@plaintext.sk>
2009-09-02 00:01 ` Re: Possible bug in PGInterval class Kris Jurka <books@ejurka.com>
@ 2009-09-02 19:01 ` Ľubomír Varga <luvar@plaintext.sk>
1 sibling, 0 replies; 4+ messages in thread
From: Ľubomír Varga @ 2009-09-02 19:01 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc
On Wednesday 02 September 2009 02:01:11 Kris Jurka wrote:
>...
> > Second, critical for me, is to not using modulo in addition. So if you
> > add 55 minutes to 55 minutes, you get 110 minutes instead of 1 hour and
> > 50 minutes.
>
> For minutes and hours, it would be OK, but when rolling hours into days or
> days into months, context is needed to know if you are near a daylight
> saving time change or how many days are in the month. For this reason we
> don't manipulate the values and leave them as is.
>
What about to add some function which will "normalize" interval and make
minutes lees than 60, hours lees than 24 and seconds lees than 60? I do it
like this:
PGInterval duration = ...;
int add = 0;
if(duration.getSeconds() > 60) {
add = (int)Math.floor(duration.getSeconds() / 60);
duration.setSeconds(duration.getSeconds() - (add * 60));
duration.setMinutes(duration.getMinutes() + add);
}
if(duration.getMinutes() > 60) {
add = duration.getMinutes() / 60;
duration.setMinutes(duration.getMinutes() - (add * 60));
duration.setHours(duration.getHours() + add);
}
if(duration.getHours() > 24) {
add = duration.getHours() / 24;
duration.setHours(duration.getHours() - (add * 24));
duration.setDays(duration.getDays() + add);
}
Just an suggestion for future generations of developers which will use
PGInterval for postprocessing selected data like me...
PS: Thanks for explanation, I fully accept that reason.
--
Odborník na všetko je zlý odborník. Ja sa snažím byť výnimkou potvrdzujúcou
pravidlo.
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2009-09-02 19:01 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-08-31 19:34 Possible bug in PGInterval class Ľubomír Varga <luvar@plaintext.sk>
2009-09-02 00:01 ` Kris Jurka <books@ejurka.com>
2009-09-02 00:03 ` Oliver Jowett <oliver@opencloud.com>
2009-09-02 19:01 ` Ľubomír Varga <luvar@plaintext.sk>
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