CmdCalendar: Migrated from Date to ISO8601d

This commit is contained in:
Paul Beckingham 2015-10-03 19:31:58 -04:00
parent 0772f7ea36
commit 26fbca7896
2 changed files with 12 additions and 13 deletions

View file

@ -30,7 +30,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <Context.h> #include <Context.h>
#include <ViewText.h> #include <ViewText.h>
#include <ISO8601.h>
#include <i18n.h> #include <i18n.h>
#include <text.h> #include <text.h>
#include <util.h> #include <util.h>
@ -75,7 +74,7 @@ int CmdCalendar::execute (std::string& output)
handleRecurrence (); handleRecurrence ();
auto tasks = context.tdb2.pending.get_tasks (); auto tasks = context.tdb2.pending.get_tasks ();
Date today; ISO8601d today;
bool getpendingdate = false; bool getpendingdate = false;
int monthsToDisplay = 1; int monthsToDisplay = 1;
int mFrom = today.month (); int mFrom = today.month ();
@ -177,7 +176,7 @@ int CmdCalendar::execute (std::string& output)
if (getpendingdate == true) if (getpendingdate == true)
{ {
// Find the oldest pending due date. // Find the oldest pending due date.
Date oldest (12, 31, 2037); ISO8601d oldest (12, 31, 2037);
for (auto& task : tasks) for (auto& task : tasks)
{ {
if (task.getStatus () == Task::pending) if (task.getStatus () == Task::pending)
@ -186,7 +185,7 @@ int CmdCalendar::execute (std::string& output)
!task.hasTag ("nocal")) !task.hasTag ("nocal"))
{ {
++countDueDates; ++countDueDates;
Date d (task.get ("due")); ISO8601d d (task.get ("due"));
if (d < oldest) oldest = d; if (d < oldest) oldest = d;
} }
} }
@ -327,10 +326,10 @@ int CmdCalendar::execute (std::string& output)
++yTo; ++yTo;
} }
Date date_after (details_mFrom, details_dFrom, details_yFrom); ISO8601d date_after (details_mFrom, details_dFrom, details_yFrom);
std::string after = date_after.toString (context.config.get ("dateformat")); std::string after = date_after.toString (context.config.get ("dateformat"));
Date date_before (mTo, 1, yTo); ISO8601d date_before (mTo, 1, yTo);
std::string before = date_before.toString (context.config.get ("dateformat")); std::string before = date_before.toString (context.config.get ("dateformat"));
// Table with due date information // Table with due date information
@ -380,7 +379,7 @@ int CmdCalendar::execute (std::string& output)
{ {
std::string holName = context.config.get ("holiday." + it.first.substr (8, it.first.size () - 13) + ".name"); std::string holName = context.config.get ("holiday." + it.first.substr (8, it.first.size () - 13) + ".name");
std::string holDate = context.config.get ("holiday." + it.first.substr (8, it.first.size () - 13) + ".date"); std::string holDate = context.config.get ("holiday." + it.first.substr (8, it.first.size () - 13) + ".date");
Date hDate (holDate.c_str (), context.config.get ("dateformat.holiday")); ISO8601d hDate (holDate.c_str (), context.config.get ("dateformat.holiday"));
if (date_after < hDate && hDate < date_before) if (date_after < hDate && hDate < date_before)
hm[hDate.toEpoch()].push_back(holName); hm[hDate.toEpoch()].push_back(holName);
@ -397,7 +396,7 @@ int CmdCalendar::execute (std::string& output)
for (auto& hm_it : hm) for (auto& hm_it : hm)
{ {
std::vector <std::string> v = hm_it.second; std::vector <std::string> v = hm_it.second;
Date hDate (hm_it.first); ISO8601d hDate (hm_it.first);
std::string d = hDate.toString (format); std::string d = hDate.toString (format);
for (size_t i = 0; i < v.size(); i++) for (size_t i = 0; i < v.size(); i++)
{ {
@ -421,7 +420,7 @@ int CmdCalendar::execute (std::string& output)
std::string CmdCalendar::renderMonths ( std::string CmdCalendar::renderMonths (
int firstMonth, int firstMonth,
int firstYear, int firstYear,
const Date& today, const ISO8601d& today,
std::vector <Task>& all, std::vector <Task>& all,
int monthsPerLine) int monthsPerLine)
{ {
@ -544,7 +543,7 @@ std::string CmdCalendar::renderMonths (
if (hol.first.substr (hol.first.size () - 4) == "date") if (hol.first.substr (hol.first.size () - 4) == "date")
{ {
std::string value = hol.second; std::string value = hol.second;
Date holDate (value.c_str (), context.config.get ("dateformat.holiday")); ISO8601d holDate (value.c_str (), context.config.get ("dateformat.holiday"));
if (holDate.day () == d && if (holDate.day () == d &&
holDate.month () == months[mpl] && holDate.month () == months[mpl] &&
holDate.year () == years[mpl]) holDate.year () == years[mpl])
@ -569,7 +568,7 @@ std::string CmdCalendar::renderMonths (
task.has ("due")) task.has ("due"))
{ {
std::string due = task.get ("due"); std::string due = task.get ("due");
Date duedmy (strtol (due.c_str(), NULL, 10)); ISO8601d duedmy (strtol (due.c_str(), NULL, 10));
if (duedmy.day () == d && if (duedmy.day () == d &&
duedmy.month () == months[mpl] && duedmy.month () == months[mpl] &&

View file

@ -29,7 +29,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <Date.h> #include <ISO8601.h>
#include <Task.h> #include <Task.h>
#include <Command.h> #include <Command.h>
@ -40,7 +40,7 @@ public:
int execute (std::string&); int execute (std::string&);
private: private:
std::string renderMonths (int, int, const Date&, std::vector <Task>&, int); std::string renderMonths (int, int, const ISO8601d&, std::vector <Task>&, int);
}; };
#endif #endif