Merge branch 'isodate' into 2.5.0

This commit is contained in:
Paul Beckingham 2015-10-07 07:40:28 -04:00
commit 79886e03ce
42 changed files with 1916 additions and 1898 deletions

View file

@ -32,7 +32,6 @@
#include <math.h>
#include <Context.h>
#include <Filter.h>
#include <Date.h>
#include <ISO8601.h>
#include <main.h>
#include <i18n.h>
@ -152,10 +151,10 @@ public:
private:
void generateBars ();
void optimizeGrid ();
Date quantize (const Date&);
ISO8601d quantize (const ISO8601d&);
Date increment (const Date&);
Date decrement (const Date&);
ISO8601d increment (const ISO8601d&);
ISO8601d decrement (const ISO8601d&);
void maxima ();
void yLabels (std::vector <int>&);
void calculateRates (std::vector <time_t>&);
@ -173,7 +172,7 @@ public:
int _estimated_bars; // Estimated bar count
int _actual_bars; // Calculated bar count
std::map <time_t, Bar> _bars; // Epoch-indexed set of bars
Date _earliest; // Date of earliest estimated bar
ISO8601d _earliest; // Date of earliest estimated bar
int _carryover_done; // Number of 'done' tasks prior to chart range
char _period; // D, W, M
std::string _title; // Additional description
@ -226,13 +225,13 @@ void Chart::scan (std::vector <Task>& tasks)
generateBars ();
// Not quantized, so that "while (xxx < now)" is inclusive.
Date now;
ISO8601d now;
time_t epoch;
for (auto& task : tasks)
{
// The entry date is when the counting starts.
Date from = quantize (Date (task.get_date ("entry")));
ISO8601d from = quantize (ISO8601d (task.get_date ("entry")));
epoch = from.toEpoch ();
if (_bars.find (epoch) != _bars.end ())
@ -246,7 +245,7 @@ void Chart::scan (std::vector <Task>& tasks)
{
if (task.has ("start"))
{
Date start = quantize (Date (task.get_date ("start")));
ISO8601d start = quantize (ISO8601d (task.get_date ("start")));
while (from < start)
{
epoch = from.toEpoch ();
@ -280,7 +279,7 @@ void Chart::scan (std::vector <Task>& tasks)
else if (status == Task::completed)
{
// Truncate history so it starts at 'earliest' for completed tasks.
Date end = quantize (Date (task.get_date ("end")));
ISO8601d end = quantize (ISO8601d (task.get_date ("end")));
epoch = end.toEpoch ();
if (_bars.find (epoch) != _bars.end ())
@ -296,7 +295,7 @@ void Chart::scan (std::vector <Task>& tasks)
if (task.has ("start"))
{
Date start = quantize (Date (task.get_date ("start")));
ISO8601d start = quantize (ISO8601d (task.get_date ("start")));
while (from < start)
{
epoch = from.toEpoch ();
@ -323,7 +322,7 @@ void Chart::scan (std::vector <Task>& tasks)
}
else
{
Date end = quantize (Date (task.get_date ("end")));
ISO8601d end = quantize (ISO8601d (task.get_date ("end")));
while (from < end)
{
epoch = from.toEpoch ();
@ -347,7 +346,7 @@ void Chart::scan (std::vector <Task>& tasks)
else if (status == Task::deleted)
{
// Skip old deleted tasks.
Date end = quantize (Date (task.get_date ("end")));
ISO8601d end = quantize (ISO8601d (task.get_date ("end")));
epoch = end.toEpoch ();
if (_bars.find (epoch) != _bars.end ())
++_bars[epoch]._removed;
@ -357,7 +356,7 @@ void Chart::scan (std::vector <Task>& tasks)
if (task.has ("start"))
{
Date start = quantize (Date (task.get_date ("start")));
ISO8601d start = quantize (ISO8601d (task.get_date ("start")));
while (from < start)
{
epoch = from.toEpoch ();
@ -376,7 +375,7 @@ void Chart::scan (std::vector <Task>& tasks)
}
else
{
Date end = quantize (Date (task.get_date ("end")));
ISO8601d end = quantize (ISO8601d (task.get_date ("end")));
while (from < end)
{
epoch = from.toEpoch ();
@ -608,7 +607,7 @@ void Chart::optimizeGrid ()
}
////////////////////////////////////////////////////////////////////////////////
Date Chart::quantize (const Date& input)
ISO8601d Chart::quantize (const ISO8601d& input)
{
if (_period == 'D') return input.startOfDay ();
if (_period == 'W') return input.startOfWeek ();
@ -618,7 +617,7 @@ Date Chart::quantize (const Date& input)
}
////////////////////////////////////////////////////////////////////////////////
Date Chart::increment (const Date& input)
ISO8601d Chart::increment (const ISO8601d& input)
{
// Move to the next period.
int d = input.day ();
@ -630,7 +629,7 @@ Date Chart::increment (const Date& input)
switch (_period)
{
case 'D':
if (++d > Date::daysInMonth (m, y))
if (++d > ISO8601d::daysInMonth (m, y))
{
d = 1;
@ -644,7 +643,7 @@ Date Chart::increment (const Date& input)
case 'W':
d += 7;
days = Date::daysInMonth (m, y);
days = ISO8601d::daysInMonth (m, y);
if (d > days)
{
d -= days;
@ -667,11 +666,11 @@ Date Chart::increment (const Date& input)
break;
}
return Date (m, d, y, 0, 0, 0);
return ISO8601d (m, d, y, 0, 0, 0);
}
////////////////////////////////////////////////////////////////////////////////
Date Chart::decrement (const Date& input)
ISO8601d Chart::decrement (const ISO8601d& input)
{
// Move to the previous period.
int d = input.day ();
@ -689,7 +688,7 @@ Date Chart::decrement (const Date& input)
--y;
}
d = Date::daysInMonth (m, y);
d = ISO8601d::daysInMonth (m, y);
}
break;
@ -703,7 +702,7 @@ Date Chart::decrement (const Date& input)
y--;
}
d += Date::daysInMonth (m, y);
d += ISO8601d::daysInMonth (m, y);
}
break;
@ -717,7 +716,7 @@ Date Chart::decrement (const Date& input)
break;
}
return Date (m, d, y, 0, 0, 0);
return ISO8601d (m, d, y, 0, 0, 0);
}
////////////////////////////////////////////////////////////////////////////////
@ -727,12 +726,12 @@ void Chart::generateBars ()
Bar bar;
// Determine the last bar date.
Date cursor;
ISO8601d cursor;
switch (_period)
{
case 'D': cursor = Date ().startOfDay (); break;
case 'W': cursor = Date ().startOfWeek (); break;
case 'M': cursor = Date ().startOfMonth (); break;
case 'D': cursor = ISO8601d ().startOfDay (); break;
case 'W': cursor = ISO8601d ().startOfWeek (); break;
case 'M': cursor = ISO8601d ().startOfMonth (); break;
}
// Iterate and determine all the other bar dates.
@ -744,7 +743,7 @@ void Chart::generateBars ()
{
case 'D': // month/day
{
std::string month = Date::monthName (cursor.month ());
std::string month = ISO8601d::monthName (cursor.month ());
bar._major_label = month.substr (0, 3);
sprintf (str, "%02d", cursor.day ());
@ -934,7 +933,7 @@ void Chart::calculateRates (std::vector <time_t>& sequence)
int current_pending = _bars[sequence.back ()]._pending;
int remaining_days = (int) (current_pending / (_fix_rate - _find_rate));
Date now;
ISO8601d now;
ISO8601p delta (remaining_days * 86400);
now += delta;

View file

@ -74,7 +74,7 @@ int CmdCalendar::execute (std::string& output)
handleRecurrence ();
auto tasks = context.tdb2.pending.get_tasks ();
Date today;
ISO8601d today;
bool getpendingdate = false;
int monthsToDisplay = 1;
int mFrom = today.month ();
@ -98,7 +98,7 @@ int CmdCalendar::execute (std::string& output)
// Set up a vector of months, for autoComplete.
std::vector <std::string> monthNames;
for (int i = 1; i <= 12; ++i)
monthNames.push_back (lowerCase (Date::monthName (i)));
monthNames.push_back (lowerCase (ISO8601d::monthName (i)));
// For autoComplete results.
std::vector <std::string> matches;
@ -139,7 +139,7 @@ int CmdCalendar::execute (std::string& output)
// "January" etc.
else if (autoComplete (lowerCase (arg), monthNames, matches, context.config.getInteger ("abbreviation.minimum")) == 1)
{
argMonth = Date::monthOfYear (matches[0]);
argMonth = ISO8601d::monthOfYear (matches[0]);
if (argMonth == -1)
throw format (STRING_CMD_CAL_BAD_MONTH, arg);
}
@ -176,7 +176,7 @@ int CmdCalendar::execute (std::string& output)
if (getpendingdate == true)
{
// Find the oldest pending due date.
Date oldest (12, 31, 2037);
ISO8601d oldest (12, 31, 2037);
for (auto& task : tasks)
{
if (task.getStatus () == Task::pending)
@ -185,7 +185,7 @@ int CmdCalendar::execute (std::string& output)
!task.hasTag ("nocal"))
{
++countDueDates;
Date d (task.get ("due"));
ISO8601d d (task.get ("due"));
if (d < oldest) oldest = d;
}
}
@ -234,7 +234,7 @@ int CmdCalendar::execute (std::string& output)
// Print month headers (cheating on the width settings, yes)
for (int i = 0 ; i < monthsPerLine ; i++)
{
std::string month = Date::monthName (nextM);
std::string month = ISO8601d::monthName (nextM);
// 12345678901234567890123456 = 26 chars wide
// ^^ = center
@ -317,7 +317,7 @@ int CmdCalendar::execute (std::string& output)
details_mFrom = 12;
--details_yFrom;
}
int details_dFrom = Date::daysInMonth (details_mFrom, details_yFrom);
int details_dFrom = ISO8601d::daysInMonth (details_mFrom, details_yFrom);
++mTo;
if (mTo == 13)
@ -326,10 +326,10 @@ int CmdCalendar::execute (std::string& output)
++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"));
Date date_before (mTo, 1, yTo);
ISO8601d date_before (mTo, 1, yTo);
std::string before = date_before.toString (context.config.get ("dateformat"));
// Table with due date information
@ -379,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 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)
hm[hDate.toEpoch()].push_back(holName);
@ -396,7 +396,7 @@ int CmdCalendar::execute (std::string& output)
for (auto& hm_it : hm)
{
std::vector <std::string> v = hm_it.second;
Date hDate (hm_it.first);
ISO8601d hDate (hm_it.first);
std::string d = hDate.toString (format);
for (size_t i = 0; i < v.size(); i++)
{
@ -420,12 +420,12 @@ int CmdCalendar::execute (std::string& output)
std::string CmdCalendar::renderMonths (
int firstMonth,
int firstYear,
const Date& today,
const ISO8601d& today,
std::vector <Task>& all,
int monthsPerLine)
{
// What day of the week does the user consider the first?
int weekStart = Date::dayOfWeek (context.config.get ("weekstart"));
int weekStart = ISO8601d::dayOfWeek (context.config.get ("weekstart"));
if (weekStart != 0 && weekStart != 1)
throw std::string (STRING_CMD_CAL_SUN_MON);
@ -440,24 +440,24 @@ std::string CmdCalendar::renderMonths (
if (weekStart == 1)
{
view.add (Column::factory ("string.right", " "));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (1), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (2), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (3), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (4), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (5), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (6), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (0), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (1), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (2), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (3), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (4), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (5), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (6), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (0), 0, 2)));
}
else
{
view.add (Column::factory ("string.right", " "));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (0), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (1), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (2), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (3), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (4), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (5), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (Date::dayName (6), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (0), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (1), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (2), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (3), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (4), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (5), 0, 2)));
view.add (Column::factory ("string.right", utf8_substr (ISO8601d::dayName (6), 0, 2)));
}
}
@ -487,7 +487,7 @@ std::string CmdCalendar::renderMonths (
years.push_back (++thisYear);
}
months.push_back (thisMonth);
daysInMonth.push_back (Date::daysInMonth (thisMonth++, thisYear));
daysInMonth.push_back (ISO8601d::daysInMonth (thisMonth++, thisYear));
}
int row = 0;
@ -510,7 +510,7 @@ std::string CmdCalendar::renderMonths (
// Loop through days in month and add to table.
for (int d = 1; d <= daysInMonth[mpl]; ++d)
{
Date temp (months[mpl], d, years[mpl]);
ISO8601d temp (months[mpl], d, years[mpl]);
int dow = temp.dayOfWeek ();
int woy = temp.weekOfYear (weekStart);
@ -543,7 +543,7 @@ std::string CmdCalendar::renderMonths (
if (hol.first.substr (hol.first.size () - 4) == "date")
{
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 &&
holDate.month () == months[mpl] &&
holDate.year () == years[mpl])
@ -568,7 +568,7 @@ std::string CmdCalendar::renderMonths (
task.has ("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 &&
duedmy.month () == months[mpl] &&

View file

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

View file

@ -166,7 +166,7 @@ std::string CmdEdit::formatDate (
std::string value = task.get (attribute);
if (value.length ())
{
Date dt (value);
ISO8601d dt (value);
value = dt.toString (dateformat);
}
@ -250,12 +250,12 @@ std::string CmdEdit::formatTask (Task task, const std::string& dateformat)
task.getAnnotations (annotations);
for (auto& anno : annotations)
{
Date dt (strtol (anno.first.substr (11).c_str (), NULL, 10));
ISO8601d dt (strtol (anno.first.substr (11).c_str (), NULL, 10));
before << " Annotation: " << dt.toString (dateformat)
<< " -- " << json::encode (anno.second) << "\n";
}
Date now;
ISO8601d now;
before << " Annotation: " << now.toString (dateformat) << " -- \n";
// Add dependencies here.
@ -379,7 +379,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
if (formatted != value)
{
context.footnote (STRING_EDIT_ENTRY_MOD);
task.set ("entry", Date(value, dateformat).toEpochString ());
task.set ("entry", ISO8601d (value, dateformat).toEpochString ());
}
}
else
@ -396,13 +396,13 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
if (formatted != value)
{
context.footnote (STRING_EDIT_START_MOD);
task.set ("start", Date(value, dateformat).toEpochString ());
task.set ("start", ISO8601d (value, dateformat).toEpochString ());
}
}
else
{
context.footnote (STRING_EDIT_START_MOD);
task.set ("start", Date(value, dateformat).toEpochString ());
task.set ("start", ISO8601d (value, dateformat).toEpochString ());
}
}
else
@ -425,7 +425,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
if (formatted != value)
{
context.footnote (STRING_EDIT_END_MOD);
task.set ("end", Date(value, dateformat).toEpochString ());
task.set ("end", ISO8601d (value, dateformat).toEpochString ());
}
}
else if (task.getStatus () != Task::deleted)
@ -452,13 +452,13 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
if (formatted != value)
{
context.footnote (STRING_EDIT_SCHED_MOD);
task.set ("scheduled", Date(value, dateformat).toEpochString ());
task.set ("scheduled", ISO8601d (value, dateformat).toEpochString ());
}
}
else
{
context.footnote (STRING_EDIT_SCHED_MOD);
task.set ("scheduled", Date(value, dateformat).toEpochString ());
task.set ("scheduled", ISO8601d (value, dateformat).toEpochString ());
}
}
else
@ -482,13 +482,13 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
if (formatted != value)
{
context.footnote (STRING_EDIT_DUE_MOD);
task.set ("due", Date(value, dateformat).toEpochString ());
task.set ("due", ISO8601d (value, dateformat).toEpochString ());
}
}
else
{
context.footnote (STRING_EDIT_DUE_MOD);
task.set ("due", Date(value, dateformat).toEpochString ());
task.set ("due", ISO8601d (value, dateformat).toEpochString ());
}
}
else
@ -519,13 +519,13 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
if (formatted != value)
{
context.footnote (STRING_EDIT_UNTIL_MOD);
task.set ("until", Date(value, dateformat).toEpochString ());
task.set ("until", ISO8601d (value, dateformat).toEpochString ());
}
}
else
{
context.footnote (STRING_EDIT_UNTIL_MOD);
task.set ("until", Date(value, dateformat).toEpochString ());
task.set ("until", ISO8601d (value, dateformat).toEpochString ());
}
}
else
@ -581,14 +581,14 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
if (formatted != value)
{
context.footnote (STRING_EDIT_WAIT_MOD);
task.set ("wait", Date(value, dateformat).toEpochString ());
task.set ("wait", ISO8601d (value, dateformat).toEpochString ());
task.setStatus (Task::waiting);
}
}
else
{
context.footnote (STRING_EDIT_WAIT_MOD);
task.set ("wait", Date(value, dateformat).toEpochString ());
task.set ("wait", ISO8601d (value, dateformat).toEpochString ());
task.setStatus (Task::waiting);
}
}
@ -642,7 +642,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
// for each line: if the annotation is the same, then it is copied; if
// the annotation is modified, then its original date may be kept; and
// if there is no corresponding id, then a new unique date is created).
Date when (value.substr (0, gap), dateformat);
ISO8601d when (value.substr (0, gap), dateformat);
// If the map already contains a annotation for a given timestamp
// we need to increment until we find an unused key
@ -688,7 +688,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
{
std::string value = findValue (after, "\n UDA " + col.first + ":");
if ((task.get (col.first) != value) && (type != "date" ||
(task.get (col.first) != Date (value, dateformat).toEpochString ())) &&
(task.get (col.first) != ISO8601d (value, dateformat).toEpochString ())) &&
(type != "duration" ||
(task.get (col.first) != (std::string) ISO8601p (value))))
{
@ -712,7 +712,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
}
else if (type == "date")
{
task.set (col.first, Date (value, dateformat).toEpochString ());
task.set (col.first, ISO8601d (value, dateformat).toEpochString ());
}
else if (type == "duration")
{

View file

@ -32,6 +32,7 @@
#include <main.h>
#include <text.h>
#include <i18n.h>
#include <ISO8601.h>
#include <CmdHistory.h>
extern Context context;
@ -70,11 +71,11 @@ int CmdHistoryMonthly::execute (std::string& output)
for (auto& task : filtered)
{
Date entry (task.get_date ("entry"));
ISO8601d entry (task.get_date ("entry"));
Date end;
ISO8601d end;
if (task.has ("end"))
end = Date (task.get_date ("end"));
end = ISO8601d (task.get_date ("end"));
time_t epoch = entry.startOfMonth ().toEpoch ();
groups[epoch] = 0;
@ -127,7 +128,7 @@ int CmdHistoryMonthly::execute (std::string& output)
totalCompleted += completedGroup [i.first];
totalDeleted += deletedGroup [i.first];
Date dt (i.first);
ISO8601d dt (i.first);
int m, d, y;
dt.toMDY (m, d, y);
@ -136,7 +137,7 @@ int CmdHistoryMonthly::execute (std::string& output)
view.set (row, 0, y);
priorYear = y;
}
view.set (row, 1, Date::monthName(m));
view.set (row, 1, ISO8601d::monthName(m));
int net = 0;
@ -232,11 +233,11 @@ int CmdHistoryAnnual::execute (std::string& output)
for (auto& task : filtered)
{
Date entry (task.get_date ("entry"));
ISO8601d entry (task.get_date ("entry"));
Date end;
ISO8601d end;
if (task.has ("end"))
end = Date (task.get_date ("end"));
end = ISO8601d (task.get_date ("end"));
time_t epoch = entry.startOfYear ().toEpoch ();
groups[epoch] = 0;
@ -288,7 +289,7 @@ int CmdHistoryAnnual::execute (std::string& output)
totalCompleted += completedGroup [i.first];
totalDeleted += deletedGroup [i.first];
Date dt (i.first);
ISO8601d dt (i.first);
int m, d, y;
dt.toMDY (m, d, y);
@ -391,11 +392,11 @@ int CmdGHistoryMonthly::execute (std::string& output)
for (auto& task : filtered)
{
Date entry (task.get_date ("entry"));
ISO8601d entry (task.get_date ("entry"));
Date end;
ISO8601d end;
if (task.has ("end"))
end = Date (task.get_date ("end"));
end = ISO8601d (task.get_date ("end"));
time_t epoch = entry.startOfMonth ().toEpoch ();
groups[epoch] = 0;
@ -468,7 +469,7 @@ int CmdGHistoryMonthly::execute (std::string& output)
totalCompleted += completedGroup[i.first];
totalDeleted += deletedGroup[i.first];
Date dt (i.first);
ISO8601d dt (i.first);
int m, d, y;
dt.toMDY (m, d, y);
@ -477,7 +478,7 @@ int CmdGHistoryMonthly::execute (std::string& output)
view.set (row, 0, y);
priorYear = y;
}
view.set (row, 1, Date::monthName(m));
view.set (row, 1, ISO8601d::monthName(m));
unsigned int addedBar = (widthOfBar * addedGroup[i.first]) / maxLine;
unsigned int completedBar = (widthOfBar * completedGroup[i.first]) / maxLine;
@ -591,11 +592,11 @@ int CmdGHistoryAnnual::execute (std::string& output)
for (auto& task : filtered)
{
Date entry (task.get_date ("entry"));
ISO8601d entry (task.get_date ("entry"));
Date end;
ISO8601d end;
if (task.has ("end"))
end = Date (task.get_date ("end"));
end = ISO8601d (task.get_date ("end"));
time_t epoch = entry.startOfYear ().toEpoch ();
groups[epoch] = 0;
@ -667,7 +668,7 @@ int CmdGHistoryAnnual::execute (std::string& output)
totalCompleted += completedGroup[i.first];
totalDeleted += deletedGroup[i.first];
Date dt (i.first);
ISO8601d dt (i.first);
int m, d, y;
dt.toMDY (m, d, y);

View file

@ -31,7 +31,6 @@
#include <Context.h>
#include <Filter.h>
#include <ISO8601.h>
#include <Date.h>
#include <main.h>
#include <text.h>
#include <i18n.h>
@ -113,7 +112,7 @@ int CmdInfo::execute (std::string& output)
view.colorHeader (label);
}
Date now;
ISO8601d now;
// id
int row = view.addRow ();
@ -133,7 +132,7 @@ int CmdInfo::execute (std::string& output)
for (auto& anno : annotations)
description += "\n"
+ std::string (indent, ' ')
+ Date (anno.first.substr (11)).toString (dateformatanno)
+ ISO8601d (anno.first.substr (11)).toString (dateformatanno)
+ " "
+ anno.second;
@ -221,14 +220,14 @@ int CmdInfo::execute (std::string& output)
// entry
row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_ENTERED);
Date dt (task.get_date ("entry"));
ISO8601d dt (task.get_date ("entry"));
std::string entry = dt.toString (dateformat);
std::string age;
std::string created = task.get ("entry");
if (created.length ())
{
Date dt (strtol (created.c_str (), NULL, 10));
ISO8601d dt (strtol (created.c_str (), NULL, 10));
age = ISO8601p (now - dt).formatVague ();
}
@ -239,7 +238,7 @@ int CmdInfo::execute (std::string& output)
{
row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_WAITING);
view.set (row, 1, Date (task.get_date ("wait")).toString (dateformat));
view.set (row, 1, ISO8601d (task.get_date ("wait")).toString (dateformat));
}
// scheduled
@ -247,7 +246,7 @@ int CmdInfo::execute (std::string& output)
{
row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_SCHED);
view.set (row, 1, Date (task.get_date ("scheduled")).toString (dateformat));
view.set (row, 1, ISO8601d (task.get_date ("scheduled")).toString (dateformat));
}
// start
@ -255,7 +254,7 @@ int CmdInfo::execute (std::string& output)
{
row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_START);
view.set (row, 1, Date (task.get_date ("start")).toString (dateformat));
view.set (row, 1, ISO8601d (task.get_date ("start")).toString (dateformat));
}
// due (colored)
@ -263,7 +262,7 @@ int CmdInfo::execute (std::string& output)
{
row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_DUE);
view.set (row, 1, Date (task.get_date ("due")).toString (dateformat));
view.set (row, 1, ISO8601d (task.get_date ("due")).toString (dateformat));
}
// end
@ -271,7 +270,7 @@ int CmdInfo::execute (std::string& output)
{
row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_END);
view.set (row, 1, Date (task.get_date ("end")).toString (dateformat));
view.set (row, 1, ISO8601d (task.get_date ("end")).toString (dateformat));
}
// until
@ -279,7 +278,7 @@ int CmdInfo::execute (std::string& output)
{
row = view.addRow ();
view.set (row, 0, STRING_CMD_INFO_UNTIL);
view.set (row, 1, Date (task.get_date ("until")).toString (dateformat));
view.set (row, 1, ISO8601d (task.get_date ("until")).toString (dateformat));
}
// modified
@ -288,7 +287,7 @@ int CmdInfo::execute (std::string& output)
row = view.addRow ();
view.set (row, 0, STRING_CMD_INFO_MODIFIED);
Date mod (task.get_date ("modified"));
ISO8601d mod (task.get_date ("modified"));
std::string age = ISO8601p (now - mod).formatVague ();
view.set (row, 1, mod.toString (dateformat) + " (" + age + ")");
}
@ -373,13 +372,13 @@ int CmdInfo::execute (std::string& output)
view.set (row, 0, col->label ());
if (type == "date")
value = Date (value).toString (dateformat);
value = ISO8601d (value).toString (dateformat);
else if (type == "duration")
{
ISO8601p iso;
std::string::size_type cursor = 0;
if (iso.parse (value, cursor))
value = (std::string) Variant ((time_t) iso._value, Variant::type_duration);
value = (std::string) Variant ((time_t) iso, Variant::type_duration);
else
value = "PT0S";
}
@ -544,7 +543,7 @@ int CmdInfo::execute (std::string& output)
{
int row = journal.addRow ();
Date timestamp (strtol (when.substr (5).c_str (), NULL, 10));
ISO8601d timestamp (strtol (when.substr (5).c_str (), NULL, 10));
journal.set (row, 0, timestamp.toString (dateformat));
Task before (previous.substr (4));

View file

@ -90,7 +90,7 @@ int CmdStats::execute (std::string& output)
std::vector <Task> filtered;
filter.subset (all, filtered);
Date now;
ISO8601d now;
time_t earliest = time (NULL);
time_t latest = 1;
int totalT = 0;
@ -235,12 +235,12 @@ int CmdStats::execute (std::string& output)
if (filtered.size ())
{
Date e (earliest);
ISO8601d e (earliest);
row = view.addRow ();
view.set (row, 0, STRING_CMD_STATS_OLDEST);
view.set (row, 1, e.toString (dateformat));
Date l (latest);
ISO8601d l (latest);
row = view.addRow ();
view.set (row, 0, STRING_CMD_STATS_NEWEST);
view.set (row, 1, l.toString (dateformat));

View file

@ -30,7 +30,7 @@
#include <Context.h>
#include <Filter.h>
#include <ViewText.h>
#include <Date.h>
#include <ISO8601.h>
#include <main.h>
#include <i18n.h>
#include <text.h>
@ -64,18 +64,18 @@ int CmdTimesheet::execute (std::string& output)
std::vector <Task> all = context.tdb2.all_tasks ();
// What day of the week does the user consider the first?
int weekStart = Date::dayOfWeek (context.config.get ("weekstart"));
int weekStart = ISO8601d::dayOfWeek (context.config.get ("weekstart"));
if (weekStart != 0 && weekStart != 1)
throw std::string (STRING_DATE_BAD_WEEKSTART);
// Determine the date of the first day of the most recent report.
Date today;
Date start;
ISO8601d today;
ISO8601d start;
start -= (((today.dayOfWeek () - weekStart) + 7) % 7) * 86400;
// Roll back to midnight.
start = Date (start.month (), start.day (), start.year ());
Date end = start + (7 * 86400);
start = ISO8601d (start.month (), start.day (), start.year ());
ISO8601d end = start + (7 * 86400);
// Determine how many reports to run.
int quantity = 1;
@ -86,7 +86,7 @@ int CmdTimesheet::execute (std::string& output)
std::stringstream out;
for (int week = 0; week < quantity; ++week)
{
Date endString (end);
ISO8601d endString (end);
endString -= 86400;
std::string title = start.toString (context.config.get ("dateformat"))
@ -114,7 +114,7 @@ int CmdTimesheet::execute (std::string& output)
// If task completed within range.
if (task.getStatus () == Task::completed)
{
Date compDate (task.get_date ("end"));
ISO8601d compDate (task.get_date ("end"));
if (compDate >= start && compDate < end)
{
Color c;
@ -129,7 +129,7 @@ int CmdTimesheet::execute (std::string& output)
if(task.has ("due"))
{
Date dt (task.get_date ("due"));
ISO8601d dt (task.get_date ("due"));
completed.set (row, 2, dt.toString (format));
}
@ -141,7 +141,7 @@ int CmdTimesheet::execute (std::string& output)
for (auto& ann : annotations)
description += "\n"
+ std::string (indent, ' ')
+ Date (ann.first.substr (11)).toString (context.config.get ("dateformat"))
+ ISO8601d (ann.first.substr (11)).toString (context.config.get ("dateformat"))
+ " "
+ ann.second;
@ -171,7 +171,7 @@ int CmdTimesheet::execute (std::string& output)
if (task.getStatus () == Task::pending &&
task.has ("start"))
{
Date startDate (task.get_date ("start"));
ISO8601d startDate (task.get_date ("start"));
if (startDate >= start && startDate < end)
{
Color c;
@ -186,7 +186,7 @@ int CmdTimesheet::execute (std::string& output)
if (task.has ("due"))
{
Date dt (task.get_date ("due"));
ISO8601d dt (task.get_date ("due"));
started.set (row, 2, dt.toString (format));
}
@ -198,7 +198,7 @@ int CmdTimesheet::execute (std::string& output)
for (auto& ann : annotations)
description += "\n"
+ std::string (indent, ' ')
+ Date (ann.first.substr (11)).toString (context.config.get ("dateformat"))
+ ISO8601d (ann.first.substr (11)).toString (context.config.get ("dateformat"))
+ " "
+ ann.second;