Selaa lähdekoodia

Address SonarLint findings in Date class

Patrick-Christopher Mattulat 1 vuosi sitten
vanhempi
commit
7a86dc4fc5
2 muutettua tiedostoa jossa 16 lisäystä ja 17 poistoa
  1. 8 8
      include/ls-std/time/Date.hpp
  2. 8 9
      source/ls-std/time/Date.cpp

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

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-14
- * Changed:         2023-02-22
+ * Changed:         2023-05-16
  *
  * */
 
@@ -34,15 +34,15 @@ namespace ls::std::time
 
       [[nodiscard]] bool after(const ls::std::time::Date &_foreignDate) const;
       [[nodiscard]] bool before(const ls::std::time::Date &_foreignDate) const;
-      [[nodiscard]] int getDay();
-      [[nodiscard]] int getHour();
-      [[nodiscard]] int getMinute();
-      [[nodiscard]] int getMonth();
-      [[nodiscard]] int getSecond();
+      [[nodiscard]] int getDay() const;
+      [[nodiscard]] int getHour() const;
+      [[nodiscard]] int getMinute() const;
+      [[nodiscard]] int getMonth() const;
+      [[nodiscard]] int getSecond() const;
       [[nodiscard]] time_t getTime() const;
-      [[nodiscard]] int getYear();
+      [[nodiscard]] int getYear() const;
       void setTime(time_t _timestamp);
-      [[nodiscard]] ::std::string toString();
+      [[nodiscard]] ::std::string toString() const;
 
     private:
 

+ 8 - 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-02-23
+ * Changed:         2023-05-16
  *
  * */
 
@@ -15,7 +15,6 @@
 
 using ls::std::core::Class;
 using ls::std::time::Date;
-using std::localtime;
 using std::put_time;
 using std::string;
 using std::stringstream;
@@ -63,32 +62,32 @@ bool Date::before(const Date &_foreignDate) const
   return this->timestamp < _foreignDate.getTime();
 }
 
-int Date::getDay()
+int Date::getDay() const
 {
   return this->localTime->tm_mday;
 }
 
-int Date::getHour()
+int Date::getHour() const
 {
   return this->localTime->tm_hour;
 }
 
-int Date::getMinute()
+int Date::getMinute() const
 {
   return this->localTime->tm_min;
 }
 
-int Date::getMonth()
+int Date::getMonth() const
 {
   return this->localTime->tm_mon + 1;
 }
 
-int Date::getSecond()
+int Date::getSecond() const
 {
   return this->localTime->tm_sec;
 }
 
-int Date::getYear()
+int Date::getYear() const
 {
   return this->localTime->tm_year + 1900;
 }
@@ -104,7 +103,7 @@ void Date::setTime(time_t _timestamp)
   this->_init();
 }
 
-string Date::toString()
+string Date::toString() const
 {
   stringstream _stream{};
   _stream << put_time(this->localTime, "%Y-%m-%d %H:%M:%S");