Patch - Display week number in calendar report
From 9eec77085dd07940c02d9071bf2a374c9a9b54c8 Mon Sep 17 00:00:00 2001 From: Federico Hernandez <ultrafredde@gmail.com> Date: Mon, 25 May 2009 09:28:38 +0200 Subject: [PATCH 2/3] Display dummy week of year number From e2fc5d537863672c53ede96607508270f02aabaf Mon Sep 17 00:00:00 2001 From: Federico Hernandez <ultrafredde@gmail.com> Date: Mon, 25 May 2009 13:43:14 +0200 Subject: [PATCH 3/3] Display weeknumbers in 'task cal' output
This commit is contained in:
@@ -7,7 +7,9 @@
|
|||||||
considered obsolete (thank to Bruce Dillahunty).
|
considered obsolete (thank to Bruce Dillahunty).
|
||||||
+ Fixed documentation errors (thanks to Thomas@BIC).
|
+ Fixed documentation errors (thanks to Thomas@BIC).
|
||||||
+ The 'weekstart' configuration variable now controls the 'calendar'
|
+ 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
|
+ Supports '--' argument to indicate that all subsequence arguments are
|
||||||
part of the description, despite what they otherwise might mean.
|
part of the description, despite what they otherwise might mean.
|
||||||
|
|
||||||
|
|||||||
@@ -192,6 +192,12 @@
|
|||||||
Defaults to "Monday".
|
Defaults to "Monday".
|
||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
|
<dt>displayweeknumber</dt>
|
||||||
|
<dd>
|
||||||
|
Determines whether or not the week number is displayed in the
|
||||||
|
calendar report. Defaults to "yes".
|
||||||
|
</dd>
|
||||||
|
|
||||||
<dt>editor</dt>
|
<dt>editor</dt>
|
||||||
<dd>
|
<dd>
|
||||||
Specifies which text editor you wish to use for when the
|
Specifies which text editor you wish to use for when the
|
||||||
|
|||||||
@@ -137,7 +137,9 @@
|
|||||||
considered obsolete (thank to Bruce Dillahunty).
|
considered obsolete (thank to Bruce Dillahunty).
|
||||||
<li>Fixed documentation errors (thanks to Thomas@BIC).
|
<li>Fixed documentation errors (thanks to Thomas@BIC).
|
||||||
<li>The 'weekstart' configuration variable now controls the 'calendar'
|
<li>The 'weekstart' configuration variable now controls the 'calendar'
|
||||||
command (thanks to Federico Hernandez).
|
report (thanks to Federico Hernandez).
|
||||||
|
<li>The 'displayweeknumber' configuration variable now controls the display
|
||||||
|
of week number in the 'calendar' report (thanks to Federico Hernandez).
|
||||||
<li>Supports '--' argument to indicate that all subsequence arguments are
|
<li>Supports '--' argument to indicate that all subsequence arguments are
|
||||||
part of the description, despite what they otherwise might mean.
|
part of the description, despite what they otherwise might mean.
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ void Config::createDefault (const std::string& home)
|
|||||||
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, "weekstart=Sunday\n");
|
||||||
|
fprintf (out, "displayweeknumber=yes\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");
|
||||||
|
|||||||
22
src/Date.cpp
22
src/Date.cpp
@@ -355,6 +355,28 @@ std::string Date::dayName (int dow)
|
|||||||
return days[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
|
int Date::dayOfWeek () const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -53,11 +53,13 @@ public:
|
|||||||
static std::string monthName (int);
|
static std::string monthName (int);
|
||||||
static void dayName (int, std::string&);
|
static void dayName (int, std::string&);
|
||||||
static std::string dayName (int);
|
static std::string dayName (int);
|
||||||
|
static int weekOfYear (const std::string&);
|
||||||
static int dayOfWeek (const std::string&);
|
static int dayOfWeek (const std::string&);
|
||||||
|
|
||||||
int month () const;
|
int month () const;
|
||||||
int day () const;
|
int day () const;
|
||||||
int year () const;
|
int year () const;
|
||||||
|
int weekOfYear (int) const;
|
||||||
int dayOfWeek () const;
|
int dayOfWeek () const;
|
||||||
|
|
||||||
bool operator== (const Date&);
|
bool operator== (const Date&);
|
||||||
|
|||||||
@@ -1594,6 +1594,9 @@ std::string renderMonths (
|
|||||||
table.setColumnJustification (i + 5, Table::right);
|
table.setColumnJustification (i + 5, Table::right);
|
||||||
table.setColumnJustification (i + 6, Table::right);
|
table.setColumnJustification (i + 6, Table::right);
|
||||||
table.setColumnJustification (i + 7, 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.
|
// At most, we need 6 rows.
|
||||||
@@ -1628,31 +1631,36 @@ std::string renderMonths (
|
|||||||
int row = 0;
|
int row = 0;
|
||||||
|
|
||||||
// Loop through months to be added on this line.
|
// 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
|
// Reset row counter for subsequent months
|
||||||
if (c != 0)
|
if (mpl != 0)
|
||||||
row = 0;
|
row = 0;
|
||||||
|
|
||||||
// Loop through days in month and add to table.
|
// 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 dow = temp.dayOfWeek ();
|
||||||
int thisCol = dow + 1 + (8 * c);
|
int woy = temp.weekOfYear (weekStart);
|
||||||
|
|
||||||
if (weekStart == 1)
|
if (conf.get ("displayweeknumber", true))
|
||||||
thisCol -= 1;
|
table.addCell (row, (8 * mpl), woy);
|
||||||
|
|
||||||
if (thisCol == (8 * c))
|
// Calculate column id.
|
||||||
thisCol +=7;
|
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);
|
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)) &&
|
||||||
today.day () == d &&
|
today.day () == d &&
|
||||||
today.month () == months.at (c) &&
|
today.month () == months.at (mpl) &&
|
||||||
today.year () == years.at (c))
|
today.year () == years.at (mpl))
|
||||||
table.setCellFg (row, thisCol, Text::cyan);
|
table.setCellFg (row, thisCol, Text::cyan);
|
||||||
|
|
||||||
std::vector <T>::iterator it;
|
std::vector <T>::iterator it;
|
||||||
@@ -1662,8 +1670,8 @@ std::string renderMonths (
|
|||||||
|
|
||||||
if ((conf.get ("color", true) || conf.get (std::string ("_forcecolor"), false)) &&
|
if ((conf.get ("color", true) || conf.get (std::string ("_forcecolor"), false)) &&
|
||||||
due.day () == d &&
|
due.day () == d &&
|
||||||
due.month () == months.at (c) &&
|
due.month () == months.at (mpl) &&
|
||||||
due.year () == years.at (c))
|
due.year () == years.at (mpl))
|
||||||
{
|
{
|
||||||
table.setCellFg (row, thisCol, Text::black);
|
table.setCellFg (row, thisCol, Text::black);
|
||||||
table.setCellBg (row, thisCol, due < today ? Text::on_red : Text::on_yellow);
|
table.setCellBg (row, thisCol, due < today ? Text::on_red : Text::on_yellow);
|
||||||
@@ -1674,7 +1682,7 @@ std::string renderMonths (
|
|||||||
int eow = 6;
|
int eow = 6;
|
||||||
if (weekStart == 1)
|
if (weekStart == 1)
|
||||||
eow = 0;
|
eow = 0;
|
||||||
if (dow == eow && d < daysInMonth.at (c))
|
if (dow == eow && d < daysInMonth.at (mpl))
|
||||||
row++;
|
row++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1698,10 +1706,10 @@ std::string handleReportCalendar (TDB& tdb, T& task, Config& conf)
|
|||||||
}
|
}
|
||||||
#endif
|
#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.
|
// fit. But if a preference is specified, and it fits, use it.
|
||||||
int preferredMonthsPerLine = (conf.get (std::string ("monthsperline"), 0));
|
int preferredMonthsPerLine = (conf.get (std::string ("monthsperline"), 0));
|
||||||
int monthsThatFit = width / 23;
|
int monthsThatFit = width / 26;
|
||||||
|
|
||||||
int monthsPerLine = monthsThatFit;
|
int monthsPerLine = monthsThatFit;
|
||||||
if (preferredMonthsPerLine != 0 && preferredMonthsPerLine < 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++)
|
for (int i = 0 ; i < monthsPerLine ; i++)
|
||||||
{
|
{
|
||||||
std::string month = Date::monthName (nextM);
|
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
|
<< month
|
||||||
<< ' '
|
<< ' '
|
||||||
<< nextY
|
<< nextY
|
||||||
<< std::setw (right) << ' ';
|
<< std::setw (rightGap) << ' ';
|
||||||
|
|
||||||
if (++nextM > 12)
|
if (++nextM > 12)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user