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:
Tomas Babej 2021-01-02 00:21:02 -05:00
parent a641e4315f
commit 2ebf4b864d
No known key found for this signature in database
GPG key ID: B0747C6578F7D2F5

View file

@ -67,10 +67,24 @@ void ColumnTypeNumeric::modify (Task& task, const std::string& value)
std::string label = " MODIFICATION ";
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);
}