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.