From fccd0d6c961d56e0034d40472a73f7cb23d5366a Mon Sep 17 00:00:00 2001 From: Federico Hernandez Date: Mon, 18 Jan 2010 03:45:49 +0100 Subject: [PATCH] Report date format Added report.X.dateformat which gives each report the possibility to have a custom format for the due dates. --- doc/man/taskrc.5 | 18 +++++++++++++++--- src/Config.cpp | 22 ++++++++++++++++++---- src/Table.cpp | 14 ++++++++++++-- src/Table.h | 2 ++ src/custom.cpp | 5 ++++- 5 files changed, 51 insertions(+), 10 deletions(-) diff --git a/doc/man/taskrc.5 b/doc/man/taskrc.5 index c3f705b1e..77314f168 100644 --- a/doc/man/taskrc.5 +++ b/doc/man/taskrc.5 @@ -154,9 +154,14 @@ tag names you have used, or just the ones used in active tasks. .B dateformat=m/d/Y .TP .B reportdateformat=m/d/Y -This is a string of characters that define how task formats dates. If -.B reportdateformat -is set it will be used for the due date in the output of reports and "task info". +.TP +.B report.X.dateformat=m/d/Y +This is a string of characters that define how task formats dates. The precedence order +for the configuration variable is report.X.dateformat then reportdateformat then dateformat. +While report.X.dateformat only formats the due date in reports, does reportdateformat format +the due date both in reports and "task info". If both of these are not set then dateformat +will be applied to the due date. Input dates as well as all other dates in reports are formatted +according to dateformat. The default value is: m/d/Y. The string should contain the characters @@ -458,6 +463,13 @@ descending sort order. The sort IDs are separated by commas This adds a filter to the report X so that only tasks matching the filter criteria are displayed in the generated report. +.TP +.B report.X.dateformat +This adds a dateformat to the report X that will be used by the "due date" column. If +it is not set then reportdateformat and dateformat will be used in this order. See the +.B DATES +section for details on the sequence placeholders. + .TP .B report.X.limit An optional value to a report limiting the number of displayed tasks in the diff --git a/src/Config.cpp b/src/Config.cpp index 6d4a2e0b2..15a61acb6 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -67,11 +67,11 @@ std::string Config::defaults = "# Dates\n" "dateformat=m/d/Y # Preferred input and display date format\n" "#reportdateformat=m/d/Y # Preferred display date format for repors\n" - "weekstart=Sunday # Sunday or Monday only\n" // TODO - "displayweeknumber=yes # Show week numbers on calendar\n" // TODO + "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.details=yes # Calendar shows information for tasks w/due dates\n" - "#calendar.details.report=list # Report to use when showing task information in cal\n" // TODO + "#calendar.details.report=list # Report to use when showing task information in cal\n" "#monthsperline=3 # Number of calendar months on a line\n" // TODO "\n" "# Color controls.\n" @@ -108,7 +108,7 @@ std::string Config::defaults = "\n" "#default.project=foo # Default project for 'add' command\n" "#default.priority=M # Default priority for 'add' command\n" - "default.command=list # When no arguments are specified\n" // TODO + "default.command=list # When no arguments are specified\n" "\n" "_forcecolor=no # Forces color to be on, even for non TTY output\n" "blanklines=true # Use more whitespace in output\n" @@ -144,6 +144,7 @@ std::string Config::defaults = "# Description: This report is ...\n" "# Sort: due+,priority-,project+\n" "# Filter: pro:x pri:H +bug limit:10\n" + "# Dateformat: due date format in reports\n" "\n" "# task long\n" "report.long.description=Lists all task, all data, matching the specified criteria\n" @@ -151,6 +152,7 @@ std::string Config::defaults = "report.long.labels=ID,Project,Pri,Added,Started,Due,Recur,Age,Tags,Description\n" "report.long.sort=due+,priority-,project+\n" "report.long.filter=status:pending\n" + "#report.long.dateformat=m/d/Y\n" "\n" "# task list\n" "report.list.description=Lists all tasks matching the specified criteria\n" @@ -158,6 +160,7 @@ std::string Config::defaults = "report.list.labels=ID,Project,Pri,Due,Active,Age,Description\n" "report.list.sort=due+,priority-,project+\n" "report.list.filter=status:pending\n" + "#report.list.dateformat=m/d/Y\n" "\n" "# task ls\n" "report.ls.description=Minimal listing of all tasks matching the specified criteria\n" @@ -165,6 +168,7 @@ std::string Config::defaults = "report.ls.labels=ID,Project,Pri,Description\n" "report.ls.sort=priority-,project+\n" "report.ls.filter=status:pending\n" + "#report.ls.dateformat=m/d/Y\n" "\n" "# task minimal\n" "report.minimal.description=A really minimal listing\n" @@ -172,6 +176,7 @@ std::string Config::defaults = "report.minimal.labels=ID,Project,Description\n" "report.minimal.sort=project+,description+\n" "report.minimal.filter=status:pending\n" + "#report.minimal.dateformat=m/d/Y\n" "\n" "# task newest\n" "report.newest.description=Shows the newest tasks\n" @@ -179,6 +184,7 @@ std::string Config::defaults = "report.newest.labels=ID,Project,Pri,Due,Active,Age,Description\n" "report.newest.sort=id-\n" "report.newest.filter=status:pending limit:10\n" + "#report.newest.dateformat=m/d/Y\n" "\n" "# task oldest\n" "report.oldest.description=Shows the oldest tasks\n" @@ -186,6 +192,7 @@ std::string Config::defaults = "report.oldest.labels=ID,Project,Pri,Due,Active,Age,Description\n" "report.oldest.sort=id+\n" "report.oldest.filter=status:pending limit:10\n" + "#report.oldest.dateformat=m/d/Y\n" "\n" "# task overdue\n" "report.overdue.description=Lists overdue tasks matching the specified criteria\n" @@ -193,6 +200,7 @@ std::string Config::defaults = "report.overdue.labels=ID,Project,Pri,Due,Active,Age,Description\n" "report.overdue.sort=due+,priority-,project+\n" "report.overdue.filter=status:pending due.before:today\n" + "#report.overdue.dateformat=m/d/Y\n" "\n" "# task active\n" "report.active.description=Lists active tasks matching the specified criteria\n" @@ -200,6 +208,7 @@ std::string Config::defaults = "report.active.labels=ID,Project,Pri,Due,Active,Age,Description\n" "report.active.sort=due+,priority-,project+\n" "report.active.filter=status:pending start.any:\n" + "#report.active.dateformat=m/d/Y\n" "\n" "# task completed\n" "report.completed.description=Lists completed tasks matching the specified criteria\n" @@ -207,6 +216,7 @@ std::string Config::defaults = "report.completed.labels=Complete,Project,Pri,Age,Description\n" "report.completed.sort=end+,priority-,project+\n" "report.completed.filter=status:completed\n" + "#report.completed.dateformat=m/d/Y\n" "\n" "# task recurring\n" "report.recurring.description=Lists recurring tasks matching the specified criteria\n" @@ -214,6 +224,7 @@ std::string Config::defaults = "report.recurring.labels=ID,Project,Pri,Due,Recur,Active,Age,Description\n" "report.recurring.sort=due+,priority-,project+\n" "report.recurring.filter=status:pending parent.any:\n" + "#report.recurring.dateformat=m/d/Y\n" "\n" "# task waiting\n" "report.waiting.description=Lists all waiting tasks matching the specified criteria\n" @@ -221,12 +232,14 @@ std::string Config::defaults = "report.waiting.labels=ID,Project,Pri,Wait,Age,Description\n" "report.waiting.sort=wait+,priority-,project+\n" "report.waiting.filter=status:waiting\n" + "#report.waiting.dateformat=m/d/Y\n" "\n" "# task all\n" "report.all.description=Lists all tasks matching the specified criteria\n" "report.all.columns=id,project,priority,due,active,age,description\n" "report.all.labels=ID,Project,Pri,Due,Active,Age,Description\n" "report.all.sort=due+,priority-,project+\n" + "#report.all.dateformat=m/d/Y\n" "\n" "# task next\n" "report.next.description=Lists the most urgent tasks\n" @@ -234,6 +247,7 @@ std::string Config::defaults = "report.next.labels=ID,Project,Pri,Due,Active,Age,Description\n" "report.next.sort=due+,priority-,project+\n" "report.next.filter=status:pending\n" + "#report.next.dateformat=m/d/Y\n" "\n"; //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Table.cpp b/src/Table.cpp index 060b5e84b..977952b42 100644 --- a/src/Table.cpp +++ b/src/Table.cpp @@ -644,6 +644,12 @@ void Table::setDateFormat (const std::string& dateFormat) mDateFormat = dateFormat; } +//////////////////////////////////////////////////////////////////////////////// +void Table::setReportName (const std::string& reportName) +{ + mReportName = reportName; +} + //////////////////////////////////////////////////////////////////////////////// int Table::rowCount () { @@ -881,7 +887,9 @@ void Table::sort (std::vector & order) else { - std::string format = context.config.get ("reportdateformat"); + std::string format = context.config.get ("report." + mReportName + ".dateformat"); + if (format == "") + format = context.config.get ("reportdateformat"); if (format == "") format = context.config.get ("dateformat"); @@ -903,7 +911,9 @@ void Table::sort (std::vector & order) else { - std::string format = context.config.get ("reportdateformat"); + std::string format = context.config.get ("report." + mReportName + ".dateformat"); + if (format == "") + format = context.config.get ("reportdateformat"); if (format == "") format = context.config.get ("dateformat"); diff --git a/src/Table.h b/src/Table.h index dfe18d04e..6ca5f2994 100644 --- a/src/Table.h +++ b/src/Table.h @@ -86,6 +86,7 @@ public: void suppressWS (); void setDateFormat (const std::string&); + void setReportName (const std::string&); int rowCount (); int columnCount (); @@ -135,6 +136,7 @@ private: // Misc... bool mSuppressWS; std::string mDateFormat; + std::string mReportName; }; #endif diff --git a/src/custom.cpp b/src/custom.cpp index 1de5b6149..1cffbd941 100644 --- a/src/custom.cpp +++ b/src/custom.cpp @@ -162,6 +162,7 @@ int runCustomReport ( Table table; table.setTableWidth (context.getWidth ()); table.setDateFormat (context.config.get ("dateformat")); + table.setReportName (report); foreach (task, tasks) table.addRow (); @@ -360,7 +361,9 @@ int runCustomReport ( table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::left); - std::string format = context.config.get ("reportdateformat"); + std::string format = context.config.get ("report." + report + ".dateformat"); + if (format == "") + format = context.config.get ("reportdateformat"); if (format == "") format = context.config.get ("dateformat");