mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-18 15:33:08 +02:00
Fix issues with year 2038 (#3052)
* Fix annotations in year 2038 Fixes #3050 * Ensure 32-bit systems work better after 2038 Without this patch, their 32-bit signed long int could overflow. This patch was done while working on reproducible builds for openSUSE.
This commit is contained in:
parent
7017d8fc31
commit
603bf075f1
11 changed files with 19 additions and 19 deletions
|
@ -417,7 +417,7 @@ bool getDOM (const std::string& name, const Task* task, Variant& value)
|
|||
{
|
||||
// annotation_1234567890
|
||||
// 0 ^11
|
||||
value = Variant ((time_t) strtol (i.first.substr (11).c_str (), NULL, 10), Variant::type_date);
|
||||
value = Variant ((time_t) strtoll (i.first.substr (11).c_str (), NULL, 10), Variant::type_date);
|
||||
return true;
|
||||
}
|
||||
else if (elements[2] == "description")
|
||||
|
|
|
@ -217,7 +217,7 @@ void TDB2::show_diff (
|
|||
const std::string& prior,
|
||||
const std::string& when)
|
||||
{
|
||||
Datetime lastChange (strtol (when.c_str (), nullptr, 10));
|
||||
Datetime lastChange (strtoll (when.c_str (), nullptr, 10));
|
||||
|
||||
// Set the colors.
|
||||
Color color_red (Context::getContext ().color () ? Context::getContext ().config.get ("color.undo.before") : "");
|
||||
|
|
|
@ -199,8 +199,8 @@ const std::string Task::identifier (bool shortened /* = false */) const
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Task::setAsNow (const std::string& att)
|
||||
{
|
||||
char now[16];
|
||||
snprintf (now, 16, "%u", (unsigned int) time (nullptr));
|
||||
char now[22];
|
||||
snprintf (now, 22, "%lli", (long long int) time (nullptr));
|
||||
set (att, now);
|
||||
|
||||
recalc_urgency = true;
|
||||
|
@ -1189,7 +1189,7 @@ void Task::addAnnotation (const std::string& description)
|
|||
|
||||
do
|
||||
{
|
||||
key = "annotation_" + format ((int) now);
|
||||
key = "annotation_" + format ((long long int) now);
|
||||
++now;
|
||||
}
|
||||
while (has (key));
|
||||
|
|
|
@ -171,7 +171,7 @@ void ColumnDescription::render (
|
|||
{
|
||||
for (const auto& i : task.getAnnotations ())
|
||||
{
|
||||
Datetime dt (strtol (i.first.substr (11).c_str (), nullptr, 10));
|
||||
Datetime dt (strtoll (i.first.substr (11).c_str (), nullptr, 10));
|
||||
description += '\n' + std::string (_indent, ' ') + dt.toString (_dateformat) + ' ' + i.second;
|
||||
}
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ void ColumnDescription::render (
|
|||
{
|
||||
for (const auto& i : task.getAnnotations ())
|
||||
{
|
||||
Datetime dt (strtol (i.first.substr (11).c_str (), nullptr, 10));
|
||||
Datetime dt (strtoll (i.first.substr (11).c_str (), nullptr, 10));
|
||||
description += ' ' + dt.toString (_dateformat) + ' ' + i.second;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -241,7 +241,7 @@ void ColumnUDADate::measure (Task& task, unsigned int& minimum, unsigned int& ma
|
|||
// rc.report.<report>.dateformat
|
||||
// rc.dateformat.report
|
||||
// rc.dateformat
|
||||
Datetime date ((time_t) strtol (value.c_str (), nullptr, 10));
|
||||
Datetime date (strtoll (value.c_str (), nullptr, 10));
|
||||
auto format = Context::getContext ().config.get ("report." + _report + ".dateformat");
|
||||
if (format == "")
|
||||
format = Context::getContext ().config.get ("dateformat.report");
|
||||
|
@ -287,7 +287,7 @@ void ColumnUDADate::render (
|
|||
format = Context::getContext ().config.get ("dateformat");
|
||||
}
|
||||
|
||||
renderStringLeft (lines, width, color, Datetime ((time_t) strtol (value.c_str (), nullptr, 10)).toString (format));
|
||||
renderStringLeft (lines, width, color, Datetime (strtoll (value.c_str (), nullptr, 10)).toString (format));
|
||||
}
|
||||
else if (_style == "indicator")
|
||||
{
|
||||
|
|
|
@ -631,7 +631,7 @@ std::string CmdCalendar::renderMonths (
|
|||
{
|
||||
if(task.has("scheduled") && !coloredWithDue) {
|
||||
std::string scheduled = task.get ("scheduled");
|
||||
Datetime scheduleddmy (strtol (scheduled.c_str(), nullptr, 10));
|
||||
Datetime scheduleddmy (strtoll (scheduled.c_str(), nullptr, 10));
|
||||
|
||||
if (scheduleddmy.sameDay (date))
|
||||
{
|
||||
|
@ -640,7 +640,7 @@ std::string CmdCalendar::renderMonths (
|
|||
}
|
||||
if(task.has("due")) {
|
||||
std::string due = task.get ("due");
|
||||
Datetime duedmy (strtol (due.c_str(), nullptr, 10));
|
||||
Datetime duedmy (strtoll (due.c_str(), nullptr, 10));
|
||||
|
||||
if (duedmy.sameDay (date))
|
||||
{
|
||||
|
|
|
@ -261,7 +261,7 @@ std::string CmdEdit::formatTask (Task task, const std::string& dateformat)
|
|||
|
||||
for (auto& anno : task.getAnnotations ())
|
||||
{
|
||||
Datetime dt (strtol (anno.first.substr (11).c_str (), nullptr, 10));
|
||||
Datetime dt (strtoll (anno.first.substr (11).c_str (), nullptr, 10));
|
||||
before << " Annotation: " << dt.toString (dateformat)
|
||||
<< " -- " << str_replace (anno.second, "\n", ANNOTATION_EDIT_MARKER) << '\n';
|
||||
}
|
||||
|
|
|
@ -240,7 +240,7 @@ int CmdInfo::execute (std::string& output)
|
|||
auto created = task.get ("entry");
|
||||
if (created.length ())
|
||||
{
|
||||
Datetime dt (strtol (created.c_str (), nullptr, 10));
|
||||
Datetime dt (strtoll (created.c_str (), nullptr, 10));
|
||||
age = Duration (now - dt).formatVague ();
|
||||
}
|
||||
|
||||
|
|
|
@ -109,13 +109,13 @@ int CmdStats::execute (std::string& output)
|
|||
if (task.is_blocked) ++blockedT;
|
||||
if (task.is_blocking) ++blockingT;
|
||||
|
||||
time_t entry = strtol (task.get ("entry").c_str (), nullptr, 10);
|
||||
time_t entry = strtoll (task.get ("entry").c_str (), nullptr, 10);
|
||||
if (entry < earliest) earliest = entry;
|
||||
if (entry > latest) latest = entry;
|
||||
|
||||
if (status == Task::completed)
|
||||
{
|
||||
time_t end = strtol (task.get ("end").c_str (), nullptr, 10);
|
||||
time_t end = strtoll (task.get ("end").c_str (), nullptr, 10);
|
||||
daysPending += (end - entry) / 86400.0;
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ int CmdSummary::execute (std::string& output)
|
|||
{
|
||||
++countPending[parent];
|
||||
|
||||
time_t entry = strtol (task.get ("entry").c_str (), nullptr, 10);
|
||||
time_t entry = strtoll (task.get ("entry").c_str (), nullptr, 10);
|
||||
if (entry)
|
||||
sumEntry[parent] = sumEntry[parent] + (double) (now - entry);
|
||||
}
|
||||
|
@ -121,8 +121,8 @@ int CmdSummary::execute (std::string& output)
|
|||
{
|
||||
++countCompleted[parent];
|
||||
|
||||
time_t entry = strtol (task.get ("entry").c_str (), nullptr, 10);
|
||||
time_t end = strtol (task.get ("end").c_str (), nullptr, 10);
|
||||
time_t entry = strtoll (task.get ("entry").c_str (), nullptr, 10);
|
||||
time_t end = strtoll (task.get ("end").c_str (), nullptr, 10);
|
||||
if (entry && end)
|
||||
sumEntry[parent] = sumEntry[parent] + (double) (end - entry);
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ std::string renderAttribute (const std::string& name, const std::string& value,
|
|||
col->type () == "date" &&
|
||||
value != "")
|
||||
{
|
||||
Datetime d ((time_t)strtol (value.c_str (), nullptr, 10));
|
||||
Datetime d ((time_t)strtoll (value.c_str (), nullptr, 10));
|
||||
if (format == "")
|
||||
return d.toString (Context::getContext ().config.get ("dateformat"));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue