mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
ColTypeDate: Converted fomr ISO8601 to Datetime/Duration
This commit is contained in:
parent
bc58b82e96
commit
5efca16748
1 changed files with 29 additions and 28 deletions
|
@ -27,7 +27,8 @@
|
||||||
#include <cmake.h>
|
#include <cmake.h>
|
||||||
#include <ColTypeDate.h>
|
#include <ColTypeDate.h>
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
#include <ISO8601.h>
|
#include <Datetime.h>
|
||||||
|
#include <Duration.h>
|
||||||
#include <Eval.h>
|
#include <Eval.h>
|
||||||
#include <Variant.h>
|
#include <Variant.h>
|
||||||
#include <Filter.h>
|
#include <Filter.h>
|
||||||
|
@ -54,16 +55,16 @@ ColumnTypeDate::ColumnTypeDate ()
|
||||||
"remaining",
|
"remaining",
|
||||||
"countdown"};
|
"countdown"};
|
||||||
|
|
||||||
ISO8601d now;
|
Datetime now;
|
||||||
now -= 125; // So that "age" is non-zero.
|
now -= 125; // So that "age" is non-zero.
|
||||||
_examples = {now.toString (context.config.get ("dateformat")),
|
_examples = {now.toString (context.config.get ("dateformat")),
|
||||||
format (now.toJulian (), 13, 12),
|
format (now.toJulian (), 13, 12),
|
||||||
now.toEpochString (),
|
now.toEpochString (),
|
||||||
now.toISO (),
|
now.toISO (),
|
||||||
ISO8601p (ISO8601d () - now).formatVague (),
|
Duration (Datetime () - now).formatVague (),
|
||||||
'-' + ISO8601p (ISO8601d () - now).formatVague (),
|
'-' + Duration (Datetime () - now).formatVague (),
|
||||||
"",
|
"",
|
||||||
ISO8601p (ISO8601d () - now).format ()};
|
Duration (Datetime () - now).format ()};
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -74,7 +75,7 @@ void ColumnTypeDate::measure (Task& task, unsigned int& minimum, unsigned int& m
|
||||||
|
|
||||||
if (task.has (_name))
|
if (task.has (_name))
|
||||||
{
|
{
|
||||||
ISO8601d date (task.get_date (_name));
|
Datetime date (task.get_date (_name));
|
||||||
|
|
||||||
if (_style == "default" ||
|
if (_style == "default" ||
|
||||||
_style == "formatted")
|
_style == "formatted")
|
||||||
|
@ -89,12 +90,12 @@ void ColumnTypeDate::measure (Task& task, unsigned int& minimum, unsigned int& m
|
||||||
if (format == "")
|
if (format == "")
|
||||||
format = context.config.get ("dateformat");
|
format = context.config.get ("dateformat");
|
||||||
|
|
||||||
minimum = maximum = ISO8601d::length (format);
|
minimum = maximum = Datetime::length (format);
|
||||||
}
|
}
|
||||||
else if (_style == "countdown")
|
else if (_style == "countdown")
|
||||||
{
|
{
|
||||||
ISO8601d now;
|
Datetime now;
|
||||||
minimum = maximum = ISO8601p (now - date).formatVague ().length ();
|
minimum = maximum = Duration (now - date).formatVague ().length ();
|
||||||
}
|
}
|
||||||
else if (_style == "julian")
|
else if (_style == "julian")
|
||||||
{
|
{
|
||||||
|
@ -110,25 +111,25 @@ void ColumnTypeDate::measure (Task& task, unsigned int& minimum, unsigned int& m
|
||||||
}
|
}
|
||||||
else if (_style == "age")
|
else if (_style == "age")
|
||||||
{
|
{
|
||||||
ISO8601d now;
|
Datetime now;
|
||||||
if (now > date)
|
if (now > date)
|
||||||
minimum = maximum = ISO8601p (now - date).formatVague ().length ();
|
minimum = maximum = Duration (now - date).formatVague ().length ();
|
||||||
else
|
else
|
||||||
minimum = maximum = ISO8601p (date - now).formatVague ().length () + 1;
|
minimum = maximum = Duration (date - now).formatVague ().length () + 1;
|
||||||
}
|
}
|
||||||
else if (_style == "relative")
|
else if (_style == "relative")
|
||||||
{
|
{
|
||||||
ISO8601d now;
|
Datetime now;
|
||||||
if (now < date)
|
if (now < date)
|
||||||
minimum = maximum = ISO8601p (date - now).formatVague ().length ();
|
minimum = maximum = Duration (date - now).formatVague ().length ();
|
||||||
else
|
else
|
||||||
minimum = maximum = ISO8601p (now - date).formatVague ().length () + 1;
|
minimum = maximum = Duration (now - date).formatVague ().length () + 1;
|
||||||
}
|
}
|
||||||
else if (_style == "remaining")
|
else if (_style == "remaining")
|
||||||
{
|
{
|
||||||
ISO8601d now;
|
Datetime now;
|
||||||
if (date > now)
|
if (date > now)
|
||||||
minimum = maximum = ISO8601p (date - now).formatVague ().length ();
|
minimum = maximum = Duration (date - now).formatVague ().length ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw format (STRING_COLUMN_BAD_FORMAT, _name, _style);
|
throw format (STRING_COLUMN_BAD_FORMAT, _name, _style);
|
||||||
|
@ -144,7 +145,7 @@ void ColumnTypeDate::render (
|
||||||
{
|
{
|
||||||
if (task.has (_name))
|
if (task.has (_name))
|
||||||
{
|
{
|
||||||
ISO8601d date (task.get_date (_name));
|
Datetime date (task.get_date (_name));
|
||||||
|
|
||||||
if (_style == "default" ||
|
if (_style == "default" ||
|
||||||
_style == "formatted")
|
_style == "formatted")
|
||||||
|
@ -165,8 +166,8 @@ void ColumnTypeDate::render (
|
||||||
}
|
}
|
||||||
else if (_style == "countdown")
|
else if (_style == "countdown")
|
||||||
{
|
{
|
||||||
ISO8601d now;
|
Datetime now;
|
||||||
renderStringRight (lines, width, color, ISO8601p (now - date).formatVague ());
|
renderStringRight (lines, width, color, Duration (now - date).formatVague ());
|
||||||
}
|
}
|
||||||
else if (_style == "julian")
|
else if (_style == "julian")
|
||||||
renderStringRight (lines, width, color, format (date.toJulian (), 13, 12));
|
renderStringRight (lines, width, color, format (date.toJulian (), 13, 12));
|
||||||
|
@ -179,26 +180,26 @@ void ColumnTypeDate::render (
|
||||||
|
|
||||||
else if (_style == "age")
|
else if (_style == "age")
|
||||||
{
|
{
|
||||||
ISO8601d now;
|
Datetime now;
|
||||||
if (now > date)
|
if (now > date)
|
||||||
renderStringLeft (lines, width, color, ISO8601p (now - date).formatVague ());
|
renderStringLeft (lines, width, color, Duration (now - date).formatVague ());
|
||||||
else
|
else
|
||||||
renderStringLeft (lines, width, color, '-' + ISO8601p (date - now).formatVague ());
|
renderStringLeft (lines, width, color, '-' + Duration (date - now).formatVague ());
|
||||||
}
|
}
|
||||||
else if (_style == "relative")
|
else if (_style == "relative")
|
||||||
{
|
{
|
||||||
ISO8601d now;
|
Datetime now;
|
||||||
if (now < date)
|
if (now < date)
|
||||||
renderStringLeft (lines, width, color, ISO8601p (date - now).formatVague ());
|
renderStringLeft (lines, width, color, Duration (date - now).formatVague ());
|
||||||
else
|
else
|
||||||
renderStringLeft (lines, width, color, '-' + ISO8601p (now - date).formatVague ());
|
renderStringLeft (lines, width, color, '-' + Duration (now - date).formatVague ());
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (_style == "remaining")
|
else if (_style == "remaining")
|
||||||
{
|
{
|
||||||
ISO8601d now;
|
Datetime now;
|
||||||
if (date > now)
|
if (date > now)
|
||||||
renderStringRight (lines, width, color, ISO8601p (date - now).formatVague ());
|
renderStringRight (lines, width, color, Duration (date - now).formatVague ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue