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

@ -155,7 +155,9 @@ tag names you have used, or just the ones used in active tasks.
.TP .TP
.B dateformat=m/d/Y .B dateformat=m/d/Y
.TP .TP
.B reportdateformat=m/d/Y .B dateformat.report=m/d/Y
.TP
.B dateformat.holiday=YMD
.TP .TP
.B report.X.dateformat=m/d/Y .B report.X.dateformat=m/d/Y
This is a string of characters that define how task formats dates. The precedence order This is a string of characters that define how task formats dates. The precedence order
@ -277,7 +279,7 @@ holiday.sysadmin.date=20100730
.RE .RE
.RS .RS
Dates are to be entered according to the setting in the dateformat variable. Dates are to be entered according to the setting in the dateformat.holiday variable.
.RE .RE
.TP .TP

34
doc/rc/holidays-SE.rc Normal file
View file

@ -0,0 +1,34 @@
holiday.nyårsdagen.name=Nyårsdagen
holiday.nyårsdagen.date=20100101
holiday.trettondedagjul.name=Trettondedag jul
holiday.trettondedagjul.date=20100106
holiday.långfredagen.name=Långfredagen
holiday.långfredagen.date=20100402
holiday.påskdagen.name=Påskdagen
holiday.påskdagen.date=20100404
holiday.annandagpåsk.name=Annandag påsk
holiday.annandagpåsk.date=20100405
holiday.valborgmässoafton.name=Valborgmässoafton
holiday.valborgmässoafton.date=20100430
holiday.förstamaj.name=Första maj
holiday.förstamaj.date=20100501
holiday.kristihimmelfärdsdag.name=Kristi Himmelsfärdsdag
holiday.kristihimmelfärdsdag.date=20100513
holiday.pingstdagen.name=Pingstdagen
holiday.pingstdagen.date=20100526
holiday.nationaldagen.name=Nationaldagen
holiday.nationaldagen.date=20100606
holiday.midsommarafton.name=Midsommarafton
holiday.midsommarafton.date=20100625
holiday.midsommardagen.name=Midsommardagen
holiday.midsommardagen.date=20100626
holiday.allahelgonsdag.name=Alla Helgons Dag
holiday.allahelgonsdag.date=20101106
holiday.julafton.name=Julafton
holiday.julafton.date=20101224
holiday.juldagen.name=Juldagen
holiday.juldagen.date=20101225
holiday.annandagjul.name=Annandag jul
holiday.annandagjul.date=20101226
holiday.nyårsafton.name=Nyårsafton
holiday.nyårsafton.date=20101231

28
doc/rc/holidays-US.rc Normal file
View file

@ -0,0 +1,28 @@
holiday.newyearsday.name=New Years Day
holiday.newyearsday.date=20100101
holiday.martinlutherkingday.name=Martin Luther King Day
holiday.martinlutherkingday.date=20100118
holiday.presidentsday.name=Presidents Day
holiday.presidentsday.date=20100215
holiday.patriotsday.name=Patriots Day
holiday.patriotsday.date=20100419
holiday.memorialday.name=Memorial Day
holiday.memorialday.date=20100531
holiday.independenceday.name=Independence Day
holiday.independenceday.date=20100704
holiday.independenceday2.name=Independence Day observed
holiday.independenceday2.date=20100705
holiday.laborday.name=Labor Day
holiday.laborday.date=20100906
holiday.columbusday.name=Columbus Day
holiday.columbusday.date=20101011
holiday.veteransdays.name=Veterans Day
holiday.veteransdays.date=20101111
holiday.thanksgiving.name=Thanksgiving Day
holiday.thanksgiving.date=20101125
holiday.christmaseve.name=Christmas Eve
holiday.christmaseve.date=20101224
holiday.christmasday.name=Christmas Day
holiday.christmasday.date=20101225
holiday.newyearseve.name=New Years Eve
holiday.newyearseve.date=20101231

View file

@ -66,14 +66,15 @@ std::string Config::defaults =
"\n" "\n"
"# Dates\n" "# Dates\n"
"dateformat=m/d/Y # Preferred input and display date format\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" "weekstart=Sunday # Sunday or Monday only\n"
"displayweeknumber=yes # Show week numbers on calendar\n" "displayweeknumber=yes # Show week numbers on calendar\n"
"due=7 # Task is considered due in 7 days\n" "due=7 # Task is considered due in 7 days\n"
"calendar.legend=yes # Display the legend on calendar\n" "calendar.legend=yes # Display the legend on calendar\n"
"#calendar.details=full # Calendar shows information for tasks w/due dates\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.details.report=list # Report to use when showing task information in cal\n"
"#calendar.holidays=none # Show public holidays on calendar\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 "#monthsperline=3 # Number of calendar months on a line\n" // TODO
"\n" "\n"
"# Color controls.\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"); std::string format = context.config.get ("report." + mReportName + ".dateformat");
if (format == "") if (format == "")
format = context.config.get ("reportdateformat"); format = context.config.get ("dateformat.report");
if (format == "") if (format == "")
format = context.config.get ("dateformat"); 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"); std::string format = context.config.get ("report." + mReportName + ".dateformat");
if (format == "") if (format == "")
format = context.config.get ("reportdateformat"); format = context.config.get ("dateformat.report");
if (format == "") if (format == "")
format = context.config.get ("dateformat"); 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.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.debug color.alternate color.calendar.today color.calendar.due color.calendar.overdue "
"color.calendar.weekend color.calendar.holiday color.calendar.weeknumber confirmation " "color.calendar.weekend color.calendar.holiday color.calendar.weeknumber confirmation "
"curses data.location dateformat reportdateformat debug default.command default.priority " "curses data.location dateformat dateformat.holiday dateformat.report debug default.command "
"default.project defaultwidth due locale displayweeknumber echo.command fontunderline " "default.priority default.project defaultwidth due locale displayweeknumber echo.command "
"locking monthsperline nag next project shadow.command shadow.file shadow.notify weekstart " "fontunderline locking monthsperline nag next project shadow.command shadow.file shadow.notify "
"editor import.synonym.id import.synonym.uuid complete.all.projects complete.all.tags " "weekstart editor import.synonym.id import.synonym.uuid complete.all.projects complete.all.tags "
#ifdef FEATURE_SHELL #ifdef FEATURE_SHELL
"shell.prompt " "shell.prompt "
#endif #endif
@ -718,6 +718,26 @@ int handleConfig (std::string &outs)
<< "'." << "'."
<< std::endl; << 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. // Check for bad values in rc.default.priority.
std::string defaultPriority = context.config.get ("default.priority"); std::string defaultPriority = context.config.get ("default.priority");
if (defaultPriority != "H" && if (defaultPriority != "H" &&

View file

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

View file

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

View file

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

View file

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