parse datetime

pull/34863/head
deanlee 1 month ago
parent 9d7b6a02f4
commit b83c1e2d7e
  1. 26
      tools/replay/route.cc
  2. 1
      tools/replay/route.h

@ -52,10 +52,7 @@ bool Route::loadFromCommaApi() {
rInfo("invalid route format");
return false;
}
struct tm tm_time = {0};
strptime(route_.timestamp.c_str(), "%Y-%m-%d--%H-%M-%S", &tm_time);
date_time_ = mktime(&tm_time);
date_time_ = strToTime(route_.timestamp);
bool load_success = data_dir_.empty() ? loadFromServer() : loadFromLocal();
if (!load_success) {
@ -89,10 +86,21 @@ bool Route::loadFromAutoSource() {
for (int i = 0; i < log_files.size(); ++i) {
addFileToSegment(i, log_files[i]);
}
route_.begin_segment = 0;
route_.end_segment = log_files.size() - 1;
static const std::regex pattern(R"(([a-z0-9]{16})\|(\d{4}-\d{2}-\d{2}--\d{2}-\d{2}-\d{2}))");
std::smatch matches;
if (std::regex_search(route_string_, matches, pattern)) {
route_.str = matches[0];
route_.dongle_id = matches[1];
route_.timestamp = matches[2];
date_time_ = strToTime(route_.timestamp);
} else {
route_.dongle_id = route_string_;
route_.timestamp = route_string_;
route_.str = route_string_;
}
route_.begin_segment = 0;
route_.end_segment = log_files.size() - 1;
return !segments_.empty();
}
@ -182,6 +190,12 @@ void Route::addFileToSegment(int n, const std::string &file) {
}
}
std::time_t Route::strToTime(const std::string &timestamp) {
struct tm tm_time = {0};
strptime(timestamp.c_str(), "%Y-%m-%d--%H-%M-%S", &tm_time);
return mktime(&tm_time);
}
// class Segment
Segment::Segment(int n, const SegmentFile &files, uint32_t flags, const std::vector<bool> &filters,

@ -58,6 +58,7 @@ protected:
bool loadFromServer(int retries = 3);
bool loadFromJson(const std::string &json);
void addFileToSegment(int seg_num, const std::string &file);
std::time_t strToTime(const std::string &timestamp);
RouteIdentifier route_ = {};
std::string data_dir_;
std::map<int, SegmentFile> segments_;

Loading…
Cancel
Save