Patch - Configurable week start day.

From 78fef7b934f6bcac7662c1646e2dd1f8ce4f3eca Mon Sep 17 00:00:00 2001
From: Federico Hernandez <ultrafredde@gmail.com>
Date: Mon, 25 May 2009 01:14:06 +0200
Subject: [PATCH] Configurable weekstart for task cal display
This commit is contained in:
Paul Beckingham 2009-05-24 20:14:49 -04:00
parent 41a6cdea22
commit d09630a3a0
2 changed files with 38 additions and 9 deletions

View file

@ -157,6 +157,7 @@ void Config::createDefault (const std::string& home)
fprintf (out, "nag=You have higher priority tasks.\n"); fprintf (out, "nag=You have higher priority tasks.\n");
fprintf (out, "locking=on\n"); fprintf (out, "locking=on\n");
fprintf (out, "#editor=vi\n"); fprintf (out, "#editor=vi\n");
fprintf (out, "weekstart=Sunday\n");
fprintf (out, "color.overdue=bold_red\n"); fprintf (out, "color.overdue=bold_red\n");
fprintf (out, "color.due=bold_yellow\n"); fprintf (out, "color.due=bold_yellow\n");

View file

@ -1540,17 +1540,36 @@ std::string renderMonths (
Table table; Table table;
table.setDateFormat (conf.get ("dateformat", "m/d/Y")); table.setDateFormat (conf.get ("dateformat", "m/d/Y"));
int weekStart = Date::dayOfWeek (conf.get ("weekstart", "Sunday"));
if ((weekStart != 0) && (weekStart != 1))
throw std::string ("The 'weekstart' configuration variable may "
"only contain 'Sunday' or 'Monday'.");
// Build table for the number of months to be displayed. // Build table for the number of months to be displayed.
for (int i = 0 ; i < (monthsPerLine * 8); i += 8) for (int i = 0 ; i < (monthsPerLine * 8); i += 8)
{ {
table.addColumn (" "); if (weekStart == 1)
table.addColumn ("Su"); {
table.addColumn ("Mo"); table.addColumn (" ");
table.addColumn ("Tu"); table.addColumn ("Mo");
table.addColumn ("We"); table.addColumn ("Tu");
table.addColumn ("Th"); table.addColumn ("We");
table.addColumn ("Fr"); table.addColumn ("Th");
table.addColumn ("Sa"); table.addColumn ("Fr");
table.addColumn ("Sa");
table.addColumn ("Su");
}
else
{
table.addColumn (" ");
table.addColumn ("Su");
table.addColumn ("Mo");
table.addColumn ("Tu");
table.addColumn ("We");
table.addColumn ("Th");
table.addColumn ("Fr");
table.addColumn ("Sa");
}
if ((conf.get ("color", true) || conf.get (std::string ("_forcecolor"), false)) && if ((conf.get ("color", true) || conf.get (std::string ("_forcecolor"), false)) &&
conf.get (std::string ("fontunderline"), "true")) conf.get (std::string ("fontunderline"), "true"))
@ -1621,6 +1640,12 @@ std::string renderMonths (
int dow = temp.dayOfWeek (); int dow = temp.dayOfWeek ();
int thisCol = dow + 1 + (8 * c); int thisCol = dow + 1 + (8 * c);
if (weekStart == 1)
thisCol -= 1;
if (thisCol == (8 * c))
thisCol +=7;
table.addCell (row, thisCol, d); table.addCell (row, thisCol, d);
if ((conf.get ("color", true) || conf.get (std::string ("_forcecolor"), false)) && if ((conf.get ("color", true) || conf.get (std::string ("_forcecolor"), false)) &&
@ -1645,7 +1670,10 @@ std::string renderMonths (
} }
// Check for end of week, and... // Check for end of week, and...
if (dow == 6 && d < daysInMonth.at (c)) int eow = 6;
if (weekStart == 1)
eow = 0;
if (dow == eow && d < daysInMonth.at (c))
row++; row++;
} }
} }