From fd759b7af2ad824149b8ef7459a5865490cee192 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 10 Aug 2018 13:00:53 +0300 Subject: Import: support for date/time in human-readable format (yyyy-mm-dd hh:mm:ss) { "history": [ { "eventType":0, "time":"2014-12-31 12:12:12", "flags":"m", "body":"boooo" }, { "eventType":0, "timeStamp":98235, "flags":"r", "body":"moooo" } ] } --- plugins/Import/src/textjson.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'plugins/Import/src') diff --git a/plugins/Import/src/textjson.cpp b/plugins/Import/src/textjson.cpp index d964d56e81..1267148550 100644 --- a/plugins/Import/src/textjson.cpp +++ b/plugins/Import/src/textjson.cpp @@ -95,7 +95,25 @@ public: return 0; dbei->eventType = (*node)["eventType"].as_int(); - dbei->timestamp = (*node)["timeStamp"].as_int(); + + dbei->timestamp = 0; + std::string szTime = (*node)["time"].as_string(); + if (!szTime.empty()) { + char c; + struct tm st = {}; + int res = sscanf(szTime.c_str(), "%4d%c%2d%c%2d %2d:%2d:%2d", &st.tm_year, &c, &st.tm_mon, &c, &st.tm_mday, &st.tm_hour, &st.tm_min, &st.tm_sec); + if (res == 8) { + st.tm_mon--; + st.tm_mday--; + st.tm_year -= 1900; + time_t tm = mktime(&st); + if (tm != -1) + dbei->timestamp = tm; + } + } + + if (dbei->timestamp == 0) + dbei->timestamp = (*node)["timeStamp"].as_int(); dbei->flags = 0; std::string szFlags = (*node)["flags"].as_string(); -- cgit v1.2.3