- 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
This commit is contained in:
Federico Hernandez
2010-12-01 23:25:13 +01:00
parent 14ab7ba7bd
commit 4ca35fb956
7 changed files with 61 additions and 6 deletions

View File

@@ -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"

View File

@@ -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 "

View File

@@ -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++;
}

View File

@@ -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');