mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Feature #43 - relative dates: +3d, -2w
- Now dates (due, wait, limit) are parsed first as Durations, and on error reparsed as Date. When a Duration is found instead of a Date, the Duration is added to the current date/time.
This commit is contained in:
parent
123a46eef9
commit
7468a2d81d
2 changed files with 34 additions and 2 deletions
34
src/Att.cpp
34
src/Att.cpp
|
@ -335,13 +335,45 @@ bool Att::validNameValue (
|
|||
// modify 'value' here accordingly.
|
||||
}
|
||||
|
||||
// Dates can now be either a date, or a duration that is added as an offset
|
||||
// to the current date.
|
||||
else if (name == "due" ||
|
||||
name == "until" ||
|
||||
name == "wait")
|
||||
{
|
||||
// Validate and convert to epoch.
|
||||
if (value != "")
|
||||
value = Date (value, context.config.get ("dateformat")).toEpochString ();
|
||||
{
|
||||
// Try parsing as a duration. If unsuccessful, try again, as a date.
|
||||
try
|
||||
{
|
||||
Date now;
|
||||
Duration dur (value);
|
||||
|
||||
if (dur.negative ())
|
||||
value = (now - (time_t)dur).toEpochString ();
|
||||
else
|
||||
value = (now + (time_t)dur).toEpochString ();
|
||||
}
|
||||
|
||||
// If the date parsing failed, try parsing as a duration. If successful,
|
||||
// add the duration to the current date. If unsuccessful, propagate the
|
||||
// original date parse error.
|
||||
|
||||
// Try parsing as a date. If unsuccessfull, throw.
|
||||
catch (...)
|
||||
{
|
||||
try
|
||||
{
|
||||
value = Date (value, context.config.get ("dateformat")).toEpochString ();
|
||||
}
|
||||
|
||||
catch (std::string& e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (name == "recur")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue