Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 3E64463497E for ; Wed, 2 Sep 2009 16:02:19 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 74448-04 for ; Wed, 2 Sep 2009 19:02:11 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from shiva.plaintext.sk (unknown [81.0.124.6]) by mail.postgresql.org (Postfix) with ESMTP id 7B0D4634600 for ; Wed, 2 Sep 2009 16:02:11 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by shiva.plaintext.sk (Postfix) with ESMTP id 057BEA02A; Wed, 2 Sep 2009 21:02:09 +0200 (CEST) X-Virus-Scanned: amavisd-new at plaintext.sk Received: from shiva.plaintext.sk ([127.0.0.1]) by localhost (shiva.plaintext.sk [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SILpksxb5U-c; Wed, 2 Sep 2009 21:01:59 +0200 (CEST) Received: from blackhorse.local (unknown [84.245.72.18]) by shiva.plaintext.sk (Postfix) with ESMTP id C4AFAA027; Wed, 2 Sep 2009 21:01:57 +0200 (CEST) From: =?utf-8?q?=C4=BDubom=C3=ADr_Varga?= Reply-To: luvar@plaintext.sk Organization: LuVar To: Kris Jurka Subject: Re: Possible bug in PGInterval class Date: Wed, 2 Sep 2009 21:01:43 +0200 User-Agent: KMail/1.9.10 Cc: pgsql-jdbc@postgresql.org References: <200908312134.12661.luvar@plaintext.sk> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200909022101.43692.luvar@plaintext.sk> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.64 tagged_above=-10 required=5 tests=BAYES_20=-0.74, RDNS_NONE=0.1 X-Spam-Level: X-Archive-Number: 200909/4 X-Sequence-Number: 19951 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=20 minutes lees than 60, hours lees than 24 and seconds lees than 60? I do it= =20 like this: PGInterval duration =3D ...; int add =3D 0; if(duration.getSeconds() > 60) { add =3D (int)Math.floor(duration.getSeconds() / 60); duration.setSeconds(duration.getSeconds() - (add * 60)); duration.setMinutes(duration.getMinutes() + add); } if(duration.getMinutes() > 60) { add =3D duration.getMinutes() / 60; duration.setMinutes(duration.getMinutes() - (add * 60)); duration.setHours(duration.getHours() + add); } =09 if(duration.getHours() > 24) { add =3D 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=20 PGInterval for postprocessing selected data like me... PS: Thanks for explanation, I fully accept that reason. =2D-=20 Odborn=C3=ADk na v=C5=A1etko je zl=C3=BD odborn=C3=ADk. Ja sa sna=C5=BE=C3= =ADm by=C5=A5 v=C3=BDnimkou potvrdzuj=C3=BAcou=20 pravidlo.