Enhancement - new age_compact column

- Added support for a new custom report column called "age_compact",
  which is a more compact version of "age" (thanks to T. Charles Yun).
This commit is contained in:
Paul Beckingham 2009-06-03 02:19:25 -04:00
parent 66bd5fc3c0
commit ac871d9e8d
4 changed files with 46 additions and 0 deletions

View file

@ -120,6 +120,27 @@ std::string formatSeconds (time_t delta)
return std::string (formatted);
}
////////////////////////////////////////////////////////////////////////////////
// Convert a quantity in seconds to a more readable format.
std::string formatSecondsCompact (time_t delta)
{
char formatted[24];
float days = (float) delta / 86400.0;
if (days > 365) sprintf (formatted, "%.1fy", (days / 365.2422));
else if (days > 84) sprintf (formatted, "%1dmo", (int) (days / 30.6));
else if (days > 13) sprintf (formatted, "%dwk", (int) (days / 7.0));
else if (days > 5.0) sprintf (formatted, "%dd", (int) days);
else if (days > 1.0) sprintf (formatted, "%.1fd", days);
else if (days * 24 > 1.0) sprintf (formatted, "%dh", (int) (days * 24.0));
else if (days * 24 * 60 > 1) sprintf (formatted, "%dm", (int) (days * 24 * 60));
else if (days * 24 * 3600 > 1) sprintf (formatted, "%ds", (int) (days * 24 * 60 * 60));
else
strcpy (formatted, "-");
return std::string (formatted);
}
////////////////////////////////////////////////////////////////////////////////
int autoComplete (
const std::string& partial,