From d04b715a5d999e4744b828083aa5905e04dc9299 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 17 Aug 2018 18:44:12 +0300 Subject: export/import with human readable timestamps according to #1490 --- plugins/Import/src/textjson.cpp | 17 ++++++++++++++++- plugins/Msg_Export/src/utils.cpp | 4 +++- src/mir_core/src/timezones.cpp | 3 +++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/plugins/Import/src/textjson.cpp b/plugins/Import/src/textjson.cpp index 1267148550..79ec9e6f99 100644 --- a/plugins/Import/src/textjson.cpp +++ b/plugins/Import/src/textjson.cpp @@ -111,7 +111,22 @@ public: dbei->timestamp = tm; } } - + else { + szTime = (*node)["isotime"].as_string(); + if (!szTime.empty()) { + struct tm st = {}; + int res = sscanf(szTime.c_str(), "%4d-%2d-%2dT%2d:%2d:%2dZ", &st.tm_year, &st.tm_mon, &st.tm_mday, &st.tm_hour, &st.tm_min, &st.tm_sec); + if (res == 6) { + 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(); diff --git a/plugins/Msg_Export/src/utils.cpp b/plugins/Msg_Export/src/utils.cpp index ddafc4b599..081ad6e86a 100755 --- a/plugins/Msg_Export/src/utils.cpp +++ b/plugins/Msg_Export/src/utils.cpp @@ -811,7 +811,9 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath if (g_bUseJson) { JSONNode pRoot; pRoot.push_back(JSONNode("type", dbei.eventType)); - pRoot.push_back(JSONNode("timeStamp", dbei.timestamp)); + + TimeZone_PrintTimeStamp(0, dbei.timestamp, L"I", szTemp, _countof(szTemp), 0); + pRoot.push_back(JSONNode("isotime", T2Utf(szTemp).get())); std::string flags; if (dbei.flags & DBEF_SENT) diff --git a/src/mir_core/src/timezones.cpp b/src/mir_core/src/timezones.cpp index d005092352..990417a6dd 100644 --- a/src/mir_core/src/timezones.cpp +++ b/src/mir_core/src/timezones.cpp @@ -306,6 +306,9 @@ MIR_CORE_DLL(int) TimeZone_PrintDateTime(HANDLE hTZ, LPCTSTR szFormat, LPTSTR sz if (tz == nullptr && (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY))) return 1; + if (tz == nullptr) + tz = &myInfo.myTZ; + SYSTEMTIME st; if (TimeZone_GetTimeZoneTime(tz, &st)) return 1; -- cgit v1.2.3