From 4ca35fb9565a5e60b284d3d464310482cd413c51 Mon Sep 17 00:00:00 2001 From: Federico Hernandez Date: Wed, 1 Dec 2010 23:25:13 +0100 Subject: [PATCH] Feature #567 - added a calendar offset that effectively changes the first month to be displayed in the calendar report (thanks to Michelle Crane) - calendar.offset turns the featue off or on - calendar.offset.value controls the number of month to be applied for the offset --- ChangeLog | 2 ++ NEWS | 6 +++++- doc/man/taskrc.5 | 10 ++++++++++ src/Config.cpp | 2 ++ src/command.cpp | 4 ++-- src/report.cpp | 23 +++++++++++++++++++++-- src/tests/cal.t | 20 +++++++++++++++++++- 7 files changed, 61 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index ac764a472..13f0aebfc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,8 @@ to a file, by setting defaultwidth to 0. + Added feature #546, which is a 'count' command that counts tasks, and is intended to help scripts that manipulate task output. + + Added feature #567, which makes it possible to apply an offset to the first + month to be displayed in the calendar report (thanks to Michelle Crane) + Fixed bug #515, which displayed an incorrect message after duplicating a non-existent task (thanks to Peter De Poorter). + Fixed bug #529, where the 'depends' attribute was not mentioned in the diff --git a/NEWS b/NEWS index 21a69e061..e11242a71 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,8 @@ New Features in taskwarrior 1.9.4 - Added highlighting for the show command that indicates which values differ from the defaults. - Added change log display to the 'info' command. + - The first month in the calendar report can now be changed with an offset + value. Please refer to the ChangeLog file for full details. There are too many to list here. @@ -34,6 +36,8 @@ New configuration options in taskwarrior 1.9.4 the 'info' command. - gc=off can be used, temporarily, to defer GC until later commands, which eliminates problems with task ID numbers for script writers. + - calendar.offset=off and calendar.offset.value=-1 to apply an offset value + to change the effective first month in the calendar report. Newly deprecated features in taskwarrior 1.9.4 @@ -44,7 +48,7 @@ Newly deprecated features in taskwarrior 1.9.4 Taskwarrior has been built and tested on the following configurations: * OS X 10.6 Snow Leopard and 10.5 Leopard - * Fedora 13 Goddard, 12 Constantine + * Fedora 14 Laughlin, 13 Goddard * Ubuntu 10.10 Maverick Meerkat, 10.04 Lucid Lynx * Debian Sid * Slackware 12.2 diff --git a/doc/man/taskrc.5 b/doc/man/taskrc.5 index fd164bf1b..4c379b0a4 100644 --- a/doc/man/taskrc.5 +++ b/doc/man/taskrc.5 @@ -467,6 +467,16 @@ is "sparse". The report to run when displaying the details of tasks with due date when running the "task calendar" command. The default value is "list". +.TP +.B calendar.offset=off +If "on" the first month in the calendar report is effectively changed by the +offset value specified in calendar.offset.value. It defaults to "off". + +.TP +.B calendar.offset.value=-1 +The offset value to apply to the first month in the calendar report. The default +value is "-1". + .TP .B calendar.holidays=full If set to full running "task calendar" will display holidays in the calendar by diff --git a/src/Config.cpp b/src/Config.cpp index f23904fcd..81f3efc1b 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -97,6 +97,8 @@ std::string Config::defaults = "calendar.legend=yes # Display the legend 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.offset=no # Apply an offset value to control the first month of the calendar\n" + "calendar.offset.value=-1 # The number of months the first month of the calendar is moved\n" "calendar.holidays=none # Show public holidays on calendar:full, sparse or none\n" "#monthsperline=3 # Number of calendar months on a line\n" "\n" diff --git a/src/command.cpp b/src/command.cpp index e713efbed..e1c4d9e09 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -891,8 +891,8 @@ int handleShow (std::string& outs) // Note that there is a leading and trailing space, to make it easier to // search for whole words. std::string recognized = - " annotations blanklines bulk burndown.bias calendar.details " - "calendar.details.report calendar.holidays calendar.legend color " + " annotations blanklines bulk burndown.bias calendar.details calendar.details.report " + "calendar.holidays calendar.legend color calendar.offset calendar.offset.value " "color.active color.due color.due.today color.blocked color.burndown.done " "color.burndown.pending color.burndown.started color.overdue color.pri.H " "color.pri.L color.pri.M color.pri.none color.recurring color.tagged " diff --git a/src/report.cpp b/src/report.cpp index e6418eee1..6476a4bcc 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -1477,10 +1477,29 @@ int handleReportCalendar (std::string& outs) yFrom = oldest.year(); } + if (context.config.getBoolean ("calendar.offset")) + { + int moffset = context.config.getInteger ("calendar.offset.value") % 12; + int yoffset = context.config.getInteger ("calendar.offset.value") / 12; + mFrom += moffset; + yFrom += yoffset; + if (mFrom < 1) + { + mFrom += 12; + yFrom--; + } + else if (mFrom > 12) + { + mFrom -= 12; + yFrom++; + } + } + mTo = mFrom + monthsToDisplay - 1; yTo = yFrom; - if (mTo > 12) { - mTo -=12; + if (mTo > 12) + { + mTo -= 12; yTo++; } diff --git a/src/tests/cal.t b/src/tests/cal.t index 45f86bf1d..a3de455f6 100755 --- a/src/tests/cal.t +++ b/src/tests/cal.t @@ -30,7 +30,7 @@ use strict; use warnings; -use Test::More tests => 76; +use Test::More tests => 87; # Create the rc file. if (open my $fh, '>', 'cal.rc') @@ -54,6 +54,7 @@ my $day = $nday; my $prevmonth = $months[($nmon-1) % 12]; my $month = $months[($nmon) % 12]; my $nextmonth = $months[($nmon+1) % 12]; +my $prevyear = $nyear + 1899; my $year = $nyear + 1900; my $nextyear = $nyear + 1901; @@ -137,6 +138,23 @@ unlike ($output, qr/March 2010/, 'March 2010 is not displayed'); like ($output, qr/April 2010/, 'April 2010 is displayed'); unlike ($output, qr/May 2010/, 'May 2010 is not displayed'); +# calendar offsets +$output = qx{../task rc:cal.rc rc.calendar.offset:on rc.monthsperline:1 cal 1 2011}; +unlike ($output, qr/November 2010/, 'November 2010 is not displayed'); +like ($output, qr/December 2010/, 'December 2010 is displayed'); +unlike ($output, qr/January 2011/, 'January 2011 is not displayed'); +$output = qx{../task rc:cal.rc rc.calendar.offset:on rc.calendar.offset.value:2 rc.monthsperline:1 cal 1 2011}; +unlike ($output, qr/January 2011/, 'January 2011 is not displayed'); +unlike ($output, qr/February 2011/, 'February 2011 is not displayed'); +like ($output, qr/March 2011/, 'March 2011 is displayed'); +unlike ($output, qr/April 2011/, 'April 2011 is not displayed'); +$output = qx{../task rc:cal.rc rc.calendar.offset:on rc.calendar.offset.value:-12 rc.monthsperline:1 cal}; +like ($output, qr/$month\S*?\s+?$prevyear/, 'Current month and year ahead are displayed'); +unlike ($output, qr/$month\S*?\s+?$year/, 'Current month and year are not displayed'); +$output = qx{../task rc:cal.rc rc.calendar.offset:on rc.calendar.offset.value:12 rc.monthsperline:1 cal}; +unlike ($output, qr/$month\S*?\s+?$year/, 'Current month and year are not displayed'); +like ($output, qr/$month\S*?\s+?$nextyear/, 'Current month and year ahead are displayed'); + # Cleanup. unlink 'pending.data'; ok (!-r 'pending.data', 'Removed pending.data');