Skip to content

Commit

Permalink
Add intervals(time) to formula language
Browse files Browse the repository at this point in the history
Fixes #4040
  • Loading branch information
amtriathlon committed Sep 13, 2021
1 parent 60430fa commit ea26efc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Core/DataFilter.cpp
Expand Up @@ -2056,11 +2056,11 @@ void Leaf::validateFilter(Context *context, DataFilterRuntime *df, Leaf *leaf)

} else if (leaf->fparms.count() >= 1) {

QRegExp symbols("^(name|start|stop|type|test|color|route|selected|date|filename)$");
QRegExp symbols("^(name|start|stop|type|test|color|route|selected|date|time|filename)$");
QString symbol=*(leaf->fparms[0]->lvalue.n);
if (!symbols.exactMatch(symbol) && df->lookupMap.value(symbol,"") == "") {
leaf->inerror = true;
DataFiltererrors << QString(tr("invalid symbol '%1', should be either a metric name or 'name|start|stop|type|test|color|route|selected|date|filename''").arg(symbol));
DataFiltererrors << QString(tr("invalid symbol '%1', should be either a metric name or 'name|start|stop|type|test|color|route|selected|date|time|filename''").arg(symbol));

}
} else if (leaf->fparms.count() >= 2) {
Expand Down Expand Up @@ -4692,6 +4692,9 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, const Result &x, long it, R
if(symbol == "date") {
value= QDate(1900,01,01).daysTo(ride->dateTime.date());
if (wantstrings) asstring = ride->dateTime.date().toString("dd MMM yyyy");
} else if(symbol == "time") {
value= QTime(0,0,0).secsTo(ride->dateTime.time().addSecs(ii->start));
if (wantstrings) asstring = time_to_string(value);
} else if(symbol == "filename") {
asstring = ride->fileName;
} else if(symbol == "name") {
Expand Down

1 comment on commit ea26efc

@liversedge
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just made a small commit to use toString("hh:mm:ss") since time_to_string is for formatting durations, it will use the smallest string it can, so for an interval that starts at midnight or thereafter is formatted truncated to 1s, 1:00 etc. Its an edge case, it just so happens I have some like that :)

Please sign in to comment.