pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ľubomír Varga <luvar@plaintext.sk>
To: Kris Jurka <books@ejurka.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Possible bug in PGInterval class
Date: Wed, 2 Sep 2009 21:01:43 +0200
Message-ID: <200909022101.43692.luvar@plaintext.sk> (raw)
In-Reply-To: <alpine.BSO.2.00.0909011954290.14550@leary.csoft.net>
References: <200908312134.12661.luvar@plaintext.sk>
	<alpine.BSO.2.00.0909011954290.14550@leary.csoft.net>

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.



view thread (4+ messages)

Message-ID: <200909022101.43692.luvar@plaintext.sk>
Permalink:  ../200909022101.43692.luvar@plaintext.sk/
Also on:    postgresql.org/message-id/200909022101.43692.luvar@plaintext.sk

 · 

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-jdbc@postgresql.org
  Cc: luvar@plaintext.sk, books@ejurka.com
  Subject: Re: Possible bug in PGInterval class
  In-Reply-To: <200909022101.43692.luvar@plaintext.sk>
  References: <200908312134.12661.luvar@plaintext.sk> <alpine.BSO.2.00.0909011954290.14550@leary.csoft.net> <200909022101.43692.luvar@plaintext.sk>

* 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