Feature #298 - Configurable recurring task count

- Added new recurrence.limit value (default 1) to control the number of
  future pending tasks generated from a recurring parent task.
- Added unit tests.
- Updated taskrc man page.
This commit is contained in:
Paul Beckingham 2010-06-13 12:45:41 -04:00
parent 78d092c588
commit bb19361956
6 changed files with 79 additions and 1 deletions

View file

@ -75,6 +75,7 @@ std::string Config::defaults =
"active.indicator=* # What to show as an active task indicator\n"
"tag.indicator=+ # What to show as a tag indicator\n"
"recurrence.indicator=R # What to show as a task recurrence indicator\n"
"recurrence.limit=1 # Number of future recurring pending tasks\n"
"\n"
"# Dates\n"
"dateformat=m/d/Y # Preferred input and display date format\n"

View file

@ -640,7 +640,7 @@ int handleShow (std::string &outs)
"next project shadow.command shadow.file shadow.notify weekstart editor "
"import.synonym.id import.synonym.uuid complete.all.projects "
"complete.all.tags search.case.sensitive hooks active.indicator tag.indicator "
"recurrence.indicator "
"recurrence.indicator recurrence.limit "
#ifdef FEATURE_SHELL
"shell.prompt "
#endif

View file

@ -156,6 +156,8 @@ bool generateDueDates (Task& parent, std::vector <Date>& allDue)
specificEnd = true;
}
int recurrence_limit = context.config.getInteger ("recurrence.limit");
int recurrence_counter = 0;
Date now;
for (Date i = due; ; i = getNextRecurrence (i, recur))
{
@ -175,6 +177,9 @@ bool generateDueDates (Task& parent, std::vector <Date>& allDue)
}
if (i > now)
++recurrence_counter;
if (recurrence_counter >= recurrence_limit)
return true;
}

63
src/tests/recur.limit.t Executable file
View file

@ -0,0 +1,63 @@
#! /usr/bin/perl
################################################################################
## task - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use Test::More tests => 6;
# Create the rc file.
if (open my $fh, '>', 'recur.rc')
{
print $fh "data.location=.\n";
close $fh;
ok (-r 'recur.rc', 'Created recur.rc');
}
# Add a recurring task, then see how many future pending tasks are
# generated by default, and by overriding rc.recurrence.limit.
qx{../task rc:recur.rc add ONE due:tomorrow recur:weekly};
my $output = qx{../task rc:recur.rc long};
my @tasks = $output =~ /(ONE)/g;
is (scalar @tasks, 1, 'recurrence.limit default to 1');
$output = qx{../task rc:recur.rc rc.recurrence.limit:4 long};
@tasks = $output =~ /(ONE)/g;
is (scalar @tasks, 4, 'recurrence.limit override to 4');
# Cleanup.
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'recur.rc';
ok (!-r 'recur.rc', 'Removed recur.rc');
exit 0;