Holidays and dates

- improved dateformat handling now defaulting to YMD set via
  dateformat.holiday variable
- fixed missing sorting in holiday table output when running
  calendar.holidays=full
- renamed reportdateformat to dateformat.report
- added config file checking for calendar.holidays and calendar.details
- added 2 holiday files for SE and US (watertown, MA)
This commit is contained in:
Federico Hernandez 2010-01-25 01:06:15 +01:00
parent 545013e839
commit 401f1b6496
10 changed files with 114 additions and 23 deletions

View file

@ -66,14 +66,15 @@ std::string Config::defaults =
"\n"
"# Dates\n"
"dateformat=m/d/Y # Preferred input and display date format\n"
"#reportdateformat=m/d/Y # Preferred display date format for repors\n"
"dateformat.holiday=YMD # Preferred input date format for holidays\n"
"dateformat.report=m/d/Y # Preferred display date format for repors\n"
"weekstart=Sunday # Sunday or Monday only\n"
"displayweeknumber=yes # Show week numbers on calendar\n"
"due=7 # Task is considered due in 7 days\n"
"calendar.legend=yes # Display the legend on calendar\n"
"#calendar.details=full # Calendar shows information for tasks w/due dates\n"
"#calendar.details.report=list # Report to use when showing task information in cal\n"
"#calendar.holidays=none # Show public holidays on calendar\n"
"calendar.details=sparse # Calendar shows information for tasks w/due dates: full, sparse or none\n"
"calendar.details.report=list # Report to use when showing task information in cal\n"
"calendar.holidays=none # Show public holidays on calendar:full, sparse or none\n"
"#monthsperline=3 # Number of calendar months on a line\n" // TODO
"\n"
"# Color controls.\n"

View file

@ -889,7 +889,7 @@ void Table::sort (std::vector <int>& order)
{
std::string format = context.config.get ("report." + mReportName + ".dateformat");
if (format == "")
format = context.config.get ("reportdateformat");
format = context.config.get ("dateformat.report");
if (format == "")
format = context.config.get ("dateformat");
@ -913,7 +913,7 @@ void Table::sort (std::vector <int>& order)
{
std::string format = context.config.get ("report." + mReportName + ".dateformat");
if (format == "")
format = context.config.get ("reportdateformat");
format = context.config.get ("dateformat.report");
if (format == "")
format = context.config.get ("dateformat");

View file

@ -654,10 +654,10 @@ int handleConfig (std::string &outs)
"color.pri.M color.pri.none color.recurring color.tagged color.footnote color.header "
"color.debug color.alternate color.calendar.today color.calendar.due color.calendar.overdue "
"color.calendar.weekend color.calendar.holiday color.calendar.weeknumber confirmation "
"curses data.location dateformat reportdateformat debug default.command default.priority "
"default.project defaultwidth due locale displayweeknumber echo.command fontunderline "
"locking monthsperline nag next project shadow.command shadow.file shadow.notify weekstart "
"editor import.synonym.id import.synonym.uuid complete.all.projects complete.all.tags "
"curses data.location dateformat dateformat.holiday dateformat.report debug default.command "
"default.priority default.project defaultwidth due locale displayweeknumber echo.command "
"fontunderline locking monthsperline nag next project shadow.command shadow.file shadow.notify "
"weekstart editor import.synonym.id import.synonym.uuid complete.all.projects complete.all.tags "
#ifdef FEATURE_SHELL
"shell.prompt "
#endif
@ -718,6 +718,26 @@ int handleConfig (std::string &outs)
<< "'."
<< std::endl;
// Check for bad values in rc.calendar.details.
std::string calendardetails = context.config.get ("calendar.details");
if (calendardetails != "full" &&
calendardetails != "sparse" &&
calendardetails != "none")
out << "Configuration error: calendar.details contains an unrecognized value '"
<< calendardetails
<< "'."
<< std::endl;
// Check for bad values in rc.calendar.holidays.
std::string calendarholidays = context.config.get ("calendar.holidays");
if (calendarholidays != "full" &&
calendarholidays != "sparse" &&
calendarholidays != "none")
out << "Configuration error: calendar.holidays contains an unrecognized value '"
<< calendarholidays
<< "'."
<< std::endl;
// Check for bad values in rc.default.priority.
std::string defaultPriority = context.config.get ("default.priority");
if (defaultPriority != "H" &&

View file

@ -363,7 +363,7 @@ int runCustomReport (
std::string format = context.config.get ("report." + report + ".dateformat");
if (format == "")
format = context.config.get ("reportdateformat");
format = context.config.get ("dateformat.report");
if (format == "")
format = context.config.get ("dateformat");

View file

@ -414,7 +414,7 @@ int handleInfo (std::string &outs)
table.addCell (row, 0, "Due");
Date dt (atoi (task->get ("due").c_str ()));
std::string format = context.config.get ("reportdateformat");
std::string format = context.config.get ("dateformat.report");
if (format == "")
format = context.config.get ("dateformat");
@ -1223,7 +1223,7 @@ int handleReportTimesheet (std::string &outs)
if (compDate >= start && compDate < end)
{
int row = completed.addRow ();
std::string format = context.config.get ("reportdateformat");
std::string format = context.config.get ("dateformat.report");
if (format == "")
format = context.config.get ("dateformat");
completed.addCell (row, 1, task->get ("project"));
@ -1282,7 +1282,7 @@ int handleReportTimesheet (std::string &outs)
if (startDate >= start && startDate < end)
{
int row = started.addRow ();
std::string format = context.config.get ("reportdateformat");
std::string format = context.config.get ("dateformat.report");
if (format == "")
format = context.config.get ("dateformat");
started.addCell (row, 1, task->get ("project"));
@ -1471,7 +1471,7 @@ std::string renderMonths (
if (hol->substr (hol->size () - 4) == "date")
{
std::string value = context.config.get (*hol);
Date holDate (value.c_str (), context.config.get ("dateformat"));
Date holDate (value.c_str (), context.config.get ("dateformat.holiday"));
if (holDate.day () == d &&
holDate.month () == months[mpl] &&
holDate.year () == years[mpl])
@ -1759,6 +1759,7 @@ int handleReportCalendar (std::string &outs)
holTable.setTableWidth (context.getWidth ());
holTable.addColumn ("Date");
holTable.addColumn ("Holiday");
holTable.sortOn (0, Table::ascendingDueDate);
if ((context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) &&
context.config.getBoolean ("fontunderline"))
@ -1781,7 +1782,7 @@ int handleReportCalendar (std::string &outs)
{
std::string holName = context.config.get ("holiday." + hol->substr (8, hol->size () - 13) + ".name");
std::string holDate = context.config.get ("holiday." + hol->substr (8, hol->size () - 13) + ".date");
Date hDate (holDate.c_str (), context.config.get ("dateformat"));
Date hDate (holDate.c_str (), context.config.get ("dateformat.holiday"));
if (date_after < hDate && hDate < date_before)
{
@ -1789,7 +1790,7 @@ int handleReportCalendar (std::string &outs)
context.config.get ("calendar.details.report") +
".dateformat");
if (format == "")
format = context.config.get ("reportdateformat");
format = context.config.get ("dateformat.report");
if (format == "")
format = context.config.get ("dateformat");

View file

@ -138,6 +138,8 @@ if (open my $fh, '>', 'details.rc')
{
print $fh "data.location=.\n",
"dateformat=YMD\n",
"dateformat.holiday=YMD\n",
"dateformat.report=YMD\n",
"calendar.details=full\n",
"calendar.details.report=list\n",
"calendar.holidays=full\n",

View file

@ -34,7 +34,8 @@ use Test::More tests => 14;
if (open my $fh, '>', 'date1.rc')
{
print $fh "data.location=.\n",
"dateformat=YMD\n";
"dateformat=YMD\n",
"dateformat.report=YMD\n";
close $fh;
ok (-r 'date1.rc', 'Created date1.rc');
}
@ -42,7 +43,8 @@ if (open my $fh, '>', 'date1.rc')
if (open my $fh, '>', 'date2.rc')
{
print $fh "data.location=.\n",
"dateformat=m/d/y\n";
"dateformat=m/d/y\n",
"dateformat.report=m/d/y\n";
close $fh;
ok (-r 'date2.rc', 'Created date2.rc');
}
@ -50,9 +52,10 @@ if (open my $fh, '>', 'date2.rc')
if (open my $fh, '>', 'date3.rc')
{
print $fh "data.location=.\n",
"dateformat=m/d/y\n",
"dateformat=m/d/y\n",
"weekstart=Monday\n",
"reportdateformat=A D B Y (vV)\n";
"dateformat.report=A D B Y (vV)\n";
close $fh;
ok (-r 'date3.rc', 'Created date3.rc');
}
@ -74,7 +77,7 @@ ok (!-r 'pending.data', 'Removed pending.data');
qx{../task rc:date3.rc add foo due:4/8/10};
$output = qx{../task rc:date3.rc list};
like ($output, qr/Thursday 08 April 2010 \(v14\)/, 'date format A D B Y (vV) parsed');
$output = qx{../task rc:date3.rc rc.reportdateformat:"D b Y - a" list};
$output = qx{../task rc:date3.rc rc.dateformat.report:"D b Y - a" list};
like ($output, qr/08 Apr 2010 - Thu/, 'date format D b Y - a parsed');
# Cleanup.