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.