Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions plotjuggler_plugins/DataLoadCSV/timestamp_parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ static constexpr size_t NUM_UNAMBIGUOUS_FORMATS =
static constexpr int64_t EPOCH_FIRST = 1400000000; // July 14, 2014
static constexpr int64_t EPOCH_LAST = 2000000000; // May 18, 2033

static std::optional<double> ParseDoubleLocaleIndependent(const std::string& str)
{
std::string normalized = str;
std::replace(normalized.begin(), normalized.end(), ',', '.');

double value;
auto result = std::from_chars(normalized.data(), normalized.data() + normalized.size(), value);

if (result.ec == std::errc())
{
return value;
}

return std::nullopt;
}

std::string Trim(const std::string& str)
{
size_t start = str.find_first_not_of(" \t\r\n");
Expand Down Expand Up @@ -226,9 +242,7 @@ std::optional<double> AutoParseTimestamp(const std::string& str)
}
else
{
std::string normalized = trimmed;
std::replace(normalized.begin(), normalized.end(), ',', '.');
return std::stod(normalized);
return ParseDoubleLocaleIndependent(trimmed);
}
}
catch (...)
Expand Down Expand Up @@ -426,9 +440,7 @@ std::optional<double> ParseWithType(const std::string& str, const ColumnTypeInfo
switch (type_info.type)
{
case ColumnType::NUMBER: {
std::string normalized = trimmed;
std::replace(normalized.begin(), normalized.end(), ',', '.');
return std::stod(normalized);
return ParseDoubleLocaleIndependent(trimmed);
}

case ColumnType::EPOCH_SECONDS:
Expand Down
1 change: 1 addition & 0 deletions plotjuggler_plugins/DataLoadCSV/timestamp_parsing.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cstdint>
#include <locale>
#include <cctype>
#include <charconv>

// Howard Hinnant's date library - header only
#include "date/date.h"
Expand Down
Loading