mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
ColTypeNumeric: Support date and duration variants
If the lexer identifies an expression as an date or a duration, it should be re-cast into integer value. Closes #2101.
This commit is contained in:
parent
a641e4315f
commit
2ebf4b864d
1 changed files with 18 additions and 4 deletions
|
@ -67,10 +67,24 @@ void ColumnTypeNumeric::modify (Task& task, const std::string& value)
|
|||
std::string label = " [1;37;43mMODIFICATION[0m ";
|
||||
Context::getContext ().debug (label + _name + " <-- '" + evaluatedValue.get_string () + "' <-- '" + value + '\'');
|
||||
|
||||
// If the result is not readily convertible to a numeric value, then this is
|
||||
// an error.
|
||||
if (evaluatedValue.type () == Variant::type_string)
|
||||
// Convert the value of the expression to the correct type if needed
|
||||
switch (evaluatedValue.type ())
|
||||
{
|
||||
// Expected variants - no conversion
|
||||
case Variant::type_integer:
|
||||
case Variant::type_real:
|
||||
break;
|
||||
// Convertible variants - convert to int
|
||||
case Variant::type_date:
|
||||
case Variant::type_duration:
|
||||
evaluatedValue.cast (Variant::type_integer);
|
||||
break;
|
||||
// Non-convertible variants
|
||||
case Variant::type_string:
|
||||
throw format ("The value '{1}' is not a valid numeric value.", evaluatedValue.get_string ());
|
||||
default:
|
||||
throw format ("Unexpected variant type: '{1}'", evaluatedValue.type ());
|
||||
}
|
||||
|
||||
task.set (_name, evaluatedValue);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue