Skip to content

CSV Datareader Plugin Timestamp Parsing Issue #1070

Open
@anirudlappathi

Description

@anirudlappathi

Error reading file | Couldn't parse timestamp
Parsing format: [None]
Time at line 1 : [2025-04-17T17:00:08]

I found that I am getting this error on the auto timestamp parsing.

#include
#include
#include
#include
#include
#include

std::optional AutoParseTimestamp(const QString& str)
{
bool is_number = false;
QString str_trimmed = str.trimmed();
double val = 0.0;

// Support the case where the timestamp is in nanoseconds / microseconds
int64_t ts = str.toLong(&is_number);
const int64_t first_ts = 1400000000; // July 14, 2017
const int64_t last_ts = 2000000000; // May 18, 2033
if (is_number)
{
// check if it is an absolute time in nanoseconds.
// convert to seconds if it is
if (ts > first_ts * 1e9 && ts < last_ts * 1e9)
{
val = double(ts) * 1e-9;
}
else if (ts > first_ts * 1e6 && ts < last_ts * 1e6)
{
// check if it is an absolute time in microseconds.
// convert to seconds if it is
val = double(ts) * 1e-6;
}
else
{
val = double(ts);
}
}
else
{
// Try a double value (seconds)
val = str.toDouble(&is_number);
}

// handle numbers with comma instead of point as decimal separator
if (!is_number)
{
static QLocale locale_with_comma(QLocale::German);
val = locale_with_comma.toDouble(str, &is_number);
}
if (!is_number)
{
QDateTime ts = QDateTime::fromString(str, Qt::ISODateWithMs);
if (ts.isValid())
{
return double(ts.toMSecsSinceEpoch()) / 1000.0;
}
else
{
return std::nullopt;
}
}
return is_number ? std::optional(val) : std::nullopt;
};

int main(int argc, char *argv[])
{
QStringList testStrings = {
"2025-04-17T17:00:08"
};

std::cout << std::fixed << std::setprecision(9);

for (const QString& testStr : testStrings) {
    std::optional<double> result = AutoParseTimestamp(testStr);
    std::cout << "Input: [" << testStr.toStdString() << "] -> Parsed (seconds): ";
    if (result) {
        std::cout << *result << std::endl;
    } else {
        std::cout << "[Failed]" << std::endl;
    }
}

return 0;

}

I created this file to test the function that PlotJuggler uses itself and it works properly.

g++ tzparse.cpp -o timestamp_parser -lQt6Core -I/usr/include/x86_64-linux-gnu/qt6 -I/usr/include/x86_64-linux-gnu/qt6/QtCore -fPIC && ./timestamp_parser
Input: [2025-04-19T22:07:29.568] -> Parsed (seconds): 1745125649.568000078

Image

I have tried out various timestamp formats and using the parser aswell but the only thing that seems to worked for me to get the data with timestamp on the x axis is using an epoch rather than a timestamp

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions