From d09630a3a04c771abd12308a14e4f4de3fd995d1 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 24 May 2009 20:14:49 -0400 Subject: [PATCH] Patch - Configurable week start day. From 78fef7b934f6bcac7662c1646e2dd1f8ce4f3eca Mon Sep 17 00:00:00 2001 From: Federico Hernandez Date: Mon, 25 May 2009 01:14:06 +0200 Subject: [PATCH] Configurable weekstart for task cal display --- src/Config.cpp | 1 + src/report.cpp | 46 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/Config.cpp b/src/Config.cpp index ac63f9871..36cf6dd5a 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -157,6 +157,7 @@ void Config::createDefault (const std::string& home) fprintf (out, "nag=You have higher priority tasks.\n"); fprintf (out, "locking=on\n"); fprintf (out, "#editor=vi\n"); + fprintf (out, "weekstart=Sunday\n"); fprintf (out, "color.overdue=bold_red\n"); fprintf (out, "color.due=bold_yellow\n"); diff --git a/src/report.cpp b/src/report.cpp index 4a4087827..135576858 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -1540,17 +1540,36 @@ std::string renderMonths ( Table table; 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. for (int i = 0 ; i < (monthsPerLine * 8); i += 8) { - table.addColumn (" "); - table.addColumn ("Su"); - table.addColumn ("Mo"); - table.addColumn ("Tu"); - table.addColumn ("We"); - table.addColumn ("Th"); - table.addColumn ("Fr"); - table.addColumn ("Sa"); + if (weekStart == 1) + { + table.addColumn (" "); + table.addColumn ("Mo"); + table.addColumn ("Tu"); + table.addColumn ("We"); + table.addColumn ("Th"); + 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)) && conf.get (std::string ("fontunderline"), "true")) @@ -1621,6 +1640,12 @@ std::string renderMonths ( int dow = temp.dayOfWeek (); int thisCol = dow + 1 + (8 * c); + if (weekStart == 1) + thisCol -= 1; + + if (thisCol == (8 * c)) + thisCol +=7; + table.addCell (row, thisCol, d); if ((conf.get ("color", true) || conf.get (std::string ("_forcecolor"), false)) && @@ -1645,7 +1670,10 @@ std::string renderMonths ( } // 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++; } }