diff --git a/ChangeLog b/ChangeLog index 4292528be..d27b1a881 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,7 +7,9 @@ considered obsolete (thank to Bruce Dillahunty). + Fixed documentation errors (thanks to Thomas@BIC). + The 'weekstart' configuration variable now controls the 'calendar' - command (thanks to Federico Hernandez). + report (thanks to Federico Hernandez). + + The 'displayweeknumber' configuration variable now controls the display + of week number in the 'calendar' report (thanks to Federico Hernandez). + Supports '--' argument to indicate that all subsequence arguments are part of the description, despite what they otherwise might mean. diff --git a/html/config.html b/html/config.html index e19e24958..c789f64fc 100644 --- a/html/config.html +++ b/html/config.html @@ -192,6 +192,12 @@ Defaults to "Monday". +
displayweeknumber
+
+ Determines whether or not the week number is displayed in the + calendar report. Defaults to "yes". +
+
editor
Specifies which text editor you wish to use for when the diff --git a/html/task.html b/html/task.html index bf2e340fb..536cc3f91 100644 --- a/html/task.html +++ b/html/task.html @@ -137,7 +137,9 @@ considered obsolete (thank to Bruce Dillahunty).
  • Fixed documentation errors (thanks to Thomas@BIC).
  • The 'weekstart' configuration variable now controls the 'calendar' - command (thanks to Federico Hernandez). + report (thanks to Federico Hernandez). +
  • The 'displayweeknumber' configuration variable now controls the display + of week number in the 'calendar' report (thanks to Federico Hernandez).
  • Supports '--' argument to indicate that all subsequence arguments are part of the description, despite what they otherwise might mean. diff --git a/src/Config.cpp b/src/Config.cpp index 36cf6dd5a..aee4287e9 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -158,6 +158,7 @@ void Config::createDefault (const std::string& home) fprintf (out, "locking=on\n"); fprintf (out, "#editor=vi\n"); fprintf (out, "weekstart=Sunday\n"); + fprintf (out, "displayweeknumber=yes\n"); fprintf (out, "color.overdue=bold_red\n"); fprintf (out, "color.due=bold_yellow\n"); diff --git a/src/Date.cpp b/src/Date.cpp index cdc5cc7d3..761526c63 100644 --- a/src/Date.cpp +++ b/src/Date.cpp @@ -355,6 +355,28 @@ std::string Date::dayName (int dow) return days[dow]; } +//////////////////////////////////////////////////////////////////////////////// +int Date::weekOfYear (int weekStart) const +{ + struct tm* t = localtime (&mT); + char weekStr[3]; + + if (weekStart == 0) + strftime(weekStr, sizeof(weekStr), "%U", t); + else if (weekStart == 1) + strftime(weekStr, sizeof(weekStr), "%V", t); + else + throw std::string ("The 'weekstart' configuration variable may " + "only contain 'Sunday' or 'Monday'."); + + int weekNumber = ::atoi (weekStr); + + if (weekStart == 0) + weekNumber += 1; + + return weekNumber; +} + //////////////////////////////////////////////////////////////////////////////// int Date::dayOfWeek () const { diff --git a/src/Date.h b/src/Date.h index c920eb18d..74c008391 100644 --- a/src/Date.h +++ b/src/Date.h @@ -53,11 +53,13 @@ public: static std::string monthName (int); static void dayName (int, std::string&); static std::string dayName (int); + static int weekOfYear (const std::string&); static int dayOfWeek (const std::string&); int month () const; int day () const; int year () const; + int weekOfYear (int) const; int dayOfWeek () const; bool operator== (const Date&); diff --git a/src/report.cpp b/src/report.cpp index 00d36c4a3..f9105f394 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -1594,6 +1594,9 @@ std::string renderMonths ( table.setColumnJustification (i + 5, Table::right); table.setColumnJustification (i + 6, Table::right); table.setColumnJustification (i + 7, Table::right); + + // This creates a nice gap between the months. + table.setColumnWidth (i + 0, 4); } // At most, we need 6 rows. @@ -1628,31 +1631,36 @@ std::string renderMonths ( int row = 0; // Loop through months to be added on this line. - for (int c = 0; c < monthsPerLine ; c++) + for (int mpl = 0; mpl < monthsPerLine ; mpl++) { // Reset row counter for subsequent months - if (c != 0) + if (mpl != 0) row = 0; // Loop through days in month and add to table. - for (int d = 1; d <= daysInMonth.at (c); ++d) + for (int d = 1; d <= daysInMonth.at (mpl); ++d) { - Date temp (months.at (c), d, years.at (c)); + Date temp (months.at (mpl), d, years.at (mpl)); int dow = temp.dayOfWeek (); - int thisCol = dow + 1 + (8 * c); + int woy = temp.weekOfYear (weekStart); - if (weekStart == 1) - thisCol -= 1; + if (conf.get ("displayweeknumber", true)) + table.addCell (row, (8 * mpl), woy); - if (thisCol == (8 * c)) - thisCol +=7; + // Calculate column id. + int thisCol = dow + // 0 = Sunday + (weekStart == 1 ? 0 : 1) + // Offset for weekStart + (8 * mpl); // Columns in 1 month + + if (thisCol == (8 * mpl)) + thisCol += 7; table.addCell (row, thisCol, d); if ((conf.get ("color", true) || conf.get (std::string ("_forcecolor"), false)) && today.day () == d && - today.month () == months.at (c) && - today.year () == years.at (c)) + today.month () == months.at (mpl) && + today.year () == years.at (mpl)) table.setCellFg (row, thisCol, Text::cyan); std::vector ::iterator it; @@ -1662,8 +1670,8 @@ std::string renderMonths ( if ((conf.get ("color", true) || conf.get (std::string ("_forcecolor"), false)) && due.day () == d && - due.month () == months.at (c) && - due.year () == years.at (c)) + due.month () == months.at (mpl) && + due.year () == years.at (mpl)) { table.setCellFg (row, thisCol, Text::black); table.setCellBg (row, thisCol, due < today ? Text::on_red : Text::on_yellow); @@ -1674,7 +1682,7 @@ std::string renderMonths ( int eow = 6; if (weekStart == 1) eow = 0; - if (dow == eow && d < daysInMonth.at (c)) + if (dow == eow && d < daysInMonth.at (mpl)) row++; } } @@ -1698,10 +1706,10 @@ std::string handleReportCalendar (TDB& tdb, T& task, Config& conf) } #endif - // Each month requires 23 text columns width. See how many will actually + // Each month requires 28 text columns width. See how many will actually // fit. But if a preference is specified, and it fits, use it. int preferredMonthsPerLine = (conf.get (std::string ("monthsperline"), 0)); - int monthsThatFit = width / 23; + int monthsThatFit = width / 26; int monthsPerLine = monthsThatFit; if (preferredMonthsPerLine != 0 && preferredMonthsPerLine < monthsThatFit) @@ -1748,14 +1756,31 @@ std::string handleReportCalendar (TDB& tdb, T& task, Config& conf) for (int i = 0 ; i < monthsPerLine ; i++) { std::string month = Date::monthName (nextM); - int left = (18 - month.length ()) / 2 + 1; - int right = 18 - left - month.length (); - out << std::setw (left) << ' ' + // 12345678901234567890123456 = 26 chars wide + // ^^ = center + // <-------> = 13 - (month.length / 2) + 1 + // <------> = 26 - above + // +--------------------------+ + // | July 2009 | + // | Mo Tu We Th Fr Sa Su | + // | 27 1 2 3 4 5 | + // | 28 6 7 8 9 10 11 12 | + // | 29 13 14 15 16 17 18 19 | + // | 30 20 21 22 23 24 25 26 | + // | 31 27 28 29 30 31 | + // +--------------------------+ + + int totalWidth = 26; + int labelWidth = month.length () + 5; // 5 = " 2009" + int leftGap = (totalWidth / 2) - (labelWidth / 2); + int rightGap = totalWidth - leftGap - labelWidth; + + out << std::setw (leftGap) << ' ' << month << ' ' << nextY - << std::setw (right) << ' '; + << std::setw (rightGap) << ' '; if (++nextM > 12) {