瀏覽代碼

Serialized time now in ISO-8601 and avoids use of ctime, which is not thread safe.

lagkey
Trevor Irons 6 年之前
父節點
當前提交
6400486605
共有 1 個檔案被更改,包括 20 行新增3 行删除
  1. 20
    3
      Modules/LemmaCore/include/LemmaObject.h

+ 20
- 3
Modules/LemmaCore/include/LemmaObject.h 查看文件

@@ -20,6 +20,10 @@
20 20
 #include <chrono>
21 21
 #include <memory>
22 22
 
23
+#include <iostream>
24
+#include <iomanip>
25
+#include <codecvt>
26
+
23 27
 namespace Lemma {
24 28
 
25 29
 /**
@@ -68,10 +72,23 @@ class LemmaObject {
68 72
             YAML::Node node = YAML::Node();
69 73
             //node.SetStyle(YAML::EmitterStyle::Flow);
70 74
             node.SetTag( GetName() );
75
+
76
+            // ctime throws warning with MSVC and may not look right in certain locales
77
+            //std::time_t now = std::chrono::system_clock::to_time_t( std::chrono::system_clock::now() );
78
+            //std::string ser_time =  std::string( std::ctime(&now) );
79
+            //ser_time.pop_back();
80
+            //node["Serialized"] = ser_time;
81
+
82
+            // Alternative formulation
71 83
             std::time_t now = std::chrono::system_clock::to_time_t( std::chrono::system_clock::now() );
72
-            std::string ser_time =  std::string( std::ctime(&now) );
73
-            ser_time.pop_back();
74
-            node["Serialized"] = ser_time;
84
+            std::stringstream out;
85
+            // use locale format
86
+            //out.imbue(std::locale("")); // use whatever is on the system
87
+            //out << std::put_time(std::localtime(& now), L"%c") ; // locale on system
88
+            // ISO-8601 format;
89
+            out << std::put_time(std::localtime(& now), "%F %T %z");
90
+            node["Serialized"] = out.str();
91
+
75 92
             node["Lemma_VERSION"] = LEMMA_VERSION;
76 93
             return node;
77 94
         };

Loading…
取消
儲存