Browse Source

Fix usage of localtime_r for Windows machines

Patrick-Christopher Mattulat 11 months ago
parent
commit
fc6f40f60c
2 changed files with 14 additions and 5 deletions
  1. 7 3
      source/ls-std/io/logging/Logger.cpp
  2. 7 2
      source/ls-std/time/Date.cpp

+ 7 - 3
source/ls-std/io/logging/Logger.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-20
- * Changed:         2023-05-18
+ * Changed:         2023-05-24
  *
  * */
 
@@ -24,7 +24,6 @@ using ls::std::io::Logger;
 using ls::std::io::LogLevel;
 using ls::std::io::LogLevelValue;
 using ls::std::io::NewLine;
-using std::localtime;
 using std::put_time;
 using std::shared_ptr;
 using std::string;
@@ -175,7 +174,12 @@ string Logger::_getTimestampString() const
   struct tm localTime
   {
   };
-  localtime_r(&timestamp, &localTime);
+#if defined(unix) || defined(__APPLE__)
+  ::localtime_r(&timestamp, &localTime);
+#endif
+#ifdef _WIN32
+  ::localtime_s(&localTime, &timestamp);
+#endif
   string timestampString{};
 
   if (this->displayTimestamp)

+ 7 - 2
source/ls-std/time/Date.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-14
- * Changed:         2023-05-19
+ * Changed:         2023-05-24
  *
  * */
 
@@ -123,5 +123,10 @@ void Date::_incrementByDays(int _value)
 
 void Date::_init()
 {
-  localtime_r(&this->timestamp, &this->localTime);
+#if defined(unix) || defined(__APPLE__)
+  ::localtime_r(&this->timestamp, &this->localTime);
+#endif
+#ifdef _WIN32
+  ::localtime_s(&this->localTime, &this->timestamp);
+#endif
 }