Date Formatting

- Some bad inefficiencies in date formatting were noticed, and when addressed,
  caused a bug to surface.  The length of a formatted date can be calculated
  from the dateformat, but was done incorrectly.  Very, very incorrectly.
- Added unit tests.
- Promoted date column-specific "countdown" size measurements up to the ColDate
  base class.  This neatly falls out from work on #1218.
- Noted a potential I18N problem in Date.cpp.
This commit is contained in:
Paul Beckingham
2013-04-01 19:49:27 -04:00
parent d895c4a249
commit 656e350291
8 changed files with 79 additions and 122 deletions

View File

@@ -95,7 +95,13 @@ void ColumnDate::measure (Task& task, unsigned int& minimum, unsigned int& maxim
if (format == "")
format = context.config.get ("dateformat");
minimum = maximum = date.toString (format).length ();
minimum = maximum = Date::length (format);
}
else if (_style == "countdown")
{
Date date ((time_t) strtol (task.get (_name).c_str (), NULL, 10));
Date now;
minimum = maximum = Duration (now - date).format ().length ();
}
else if (_style == "julian")
{
@@ -134,7 +140,7 @@ void ColumnDate::render (
// Determine the output date format, which uses a hierarchy of definitions.
// rc.report.<report>.dateformat
// rc.dateformat.report
// rc.dateformat.
// rc.dateformat
std::string format = context.config.get ("report." + _report + ".dateformat");
if (format == "")
format = context.config.get ("dateformat.report");
@@ -147,6 +153,16 @@ void ColumnDate::render (
Date ((time_t) strtol (task.get (_name).c_str (), NULL, 10))
.toString (format), width)));
}
else if (_style == "countdown")
{
Date date ((time_t) strtol (task.get (_name).c_str (), NULL, 10));
Date now;
lines.push_back (
color.colorize (
rightJustify (
Duration (now - date).format (), width)));
}
else if (_style == "julian")
{
lines.push_back (