Incorrect results from RelativeTime::getDescription()


#1

RelativeTime::getDescription() produces incorrect results in some situation:

RelativeTime(60.0).getDescription() // returns an empty string RelativeTime(60.0 * 60.0).getDescription() // returns "59 mins" RelativeTime(60.0 * 60.0 * 24.0).getDescription() // returns "23 hrs 59 mins" RelativeTime(60.0 * 60.0 * 24.0 * 7.0).getDescription() // returns "1 week 6 days"
This seems to happen due to rounding errors. If the code of the RelativeTime class gets changed to this:

[code]double RelativeTime::inMinutes() const throw()
{
return seconds / 60.0;
}

double RelativeTime::inHours() const throw()
{
return seconds / (60.0 * 60.0);
}

double RelativeTime::inDays() const throw()
{
return seconds / (60.0 * 60.0 * 24.0);
}

double RelativeTime::inWeeks() const throw()
{
return seconds / (60.0 * 60.0 * 24.0 * 7.0);
}[/code]
the 4 samples above produce correct results.

Also I would suggest to return “0 sec” for RelativeTime(0).getDescription() instead of “0”. Or perhaps have the possibility to set the unit to be used for values that are to small to be displayed and so get rounded to “0”. The default for this would be an empty string, this way it wouldn’t break the current behavior.


#2

Strange - I just tried this but it all worked correctly! I’m using windows, so I guess maybe you’re on a ppc mac or something where the floating point unit is subtly different?

Fair point though, I’ll certainly change it like you suggested if that’s all it takes to sort it out.

I think I remember making it return “0” because it looked better in tracktion when you have columns of lengths. Good idea about passing it a default unit though, I’ll probably go for that - thanks!


#3

I can reproduce the incorrect results on 3 pc’s: 2x WinXP + AMD Athlon XP, 1x Ubuntu + AMD Athlon XP


#4

Must be because your app is putting the CPU into a different rounding mode then. Anyway, I’ve changed it now so should all work fine in future.


#5