Made the code for colorizing the calendar a little more dry.

This commit is contained in:
DanielMowitz
2021-04-16 00:39:20 +02:00
committed by Tomas Babej
parent affcd82466
commit dc5ebfa612

View File

@@ -510,9 +510,9 @@ std::string CmdCalendar::renderMonths (
// Loop through days in month and add to table. // Loop through days in month and add to table.
for (int d = 1; d <= daysInMonth[mpl]; ++d) for (int d = 1; d <= daysInMonth[mpl]; ++d)
{ {
Datetime temp (years[mpl], months[mpl], d); Datetime date (years[mpl], months[mpl], d);
auto dow = temp.dayOfWeek (); auto dow = date.dayOfWeek ();
auto woy = temp.week (); auto woy = date.week ();
if (Context::getContext ().config.getBoolean ("displayweeknumber")) if (Context::getContext ().config.getBoolean ("displayweeknumber"))
view.set (row, view.set (row,
@@ -548,17 +548,13 @@ std::string CmdCalendar::renderMonths (
{ {
std::string value = hol.second; std::string value = hol.second;
Datetime holDate (value.c_str (), Context::getContext ().config.get ("dateformat.holiday")); Datetime holDate (value.c_str (), Context::getContext ().config.get ("dateformat.holiday"));
if (holDate.day () == d && if (holDate.sameDay (date))
holDate.month () == months[mpl] &&
holDate.year () == years[mpl])
cellColor.blend (color_holiday); cellColor.blend (color_holiday);
} }
} }
// colorize today // colorize today
if (today.day () == d && if (today.sameDay (date))
today.month () == months.at (mpl) &&
today.year () == years.at (mpl))
cellColor.blend (color_today); cellColor.blend (color_today);
// colorize due tasks // colorize due tasks
@@ -576,9 +572,7 @@ std::string CmdCalendar::renderMonths (
std::string due = task.get ("due"); std::string due = task.get ("due");
Datetime duedmy (strtol (due.c_str(), nullptr, 10)); Datetime duedmy (strtol (due.c_str(), nullptr, 10));
if (duedmy.day () == d && if (duedmy.sameDay (date))
duedmy.month () == months[mpl] &&
duedmy.year () == years[mpl])
{ {
switch (task.getDateState ("due")) switch (task.getDateState ("due"))
{ {