Browse Source

Fix SonarLint findings in Date class

Patrick-Christopher Mattulat 1 year ago
parent
commit
1392a02c4b
2 changed files with 11 additions and 11 deletions
  1. 2 2
      include/ls-std/time/Date.hpp
  2. 9 9
      source/ls-std/time/Date.cpp

+ 2 - 2
include/ls-std/time/Date.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-14
- * Changed:         2023-05-16
+ * Changed:         2023-05-19
  *
  * */
 
@@ -47,7 +47,7 @@ namespace ls::std::time
     private:
 
       time_t timestamp{};
-      tm *localTime{};
+      tm localTime{};
 
       void _decrementByDays(int _value);
       void _incrementByDays(int _value);

+ 9 - 9
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-16
+ * Changed:         2023-05-19
  *
  * */
 
@@ -64,32 +64,32 @@ bool Date::before(const Date &_foreignDate) const
 
 int Date::getDay() const
 {
-  return this->localTime->tm_mday;
+  return this->localTime.tm_mday;
 }
 
 int Date::getHour() const
 {
-  return this->localTime->tm_hour;
+  return this->localTime.tm_hour;
 }
 
 int Date::getMinute() const
 {
-  return this->localTime->tm_min;
+  return this->localTime.tm_min;
 }
 
 int Date::getMonth() const
 {
-  return this->localTime->tm_mon + 1;
+  return this->localTime.tm_mon + 1;
 }
 
 int Date::getSecond() const
 {
-  return this->localTime->tm_sec;
+  return this->localTime.tm_sec;
 }
 
 int Date::getYear() const
 {
-  return this->localTime->tm_year + 1900;
+  return this->localTime.tm_year + 1900;
 }
 
 time_t Date::getTime() const
@@ -106,7 +106,7 @@ void Date::setTime(time_t _timestamp)
 string Date::toString() const
 {
   stringstream _stream{};
-  _stream << put_time(this->localTime, "%Y-%m-%d %H:%M:%S");
+  _stream << put_time(&this->localTime, "%Y-%m-%d %H:%M:%S");
 
   return _stream.str();
 }
@@ -123,5 +123,5 @@ void Date::_incrementByDays(int _value)
 
 void Date::_init()
 {
-  this->localTime = localtime(&this->timestamp);
+  localtime_r(&this->timestamp, &this->localTime);
 }