Browse Source

Extended Date class

- implemented "-" operator for subtract n days from
actual date
- extended tests for Date class
Patrick-Laptop 4 years ago
parent
commit
f5ca2fcd9d
3 changed files with 17 additions and 2 deletions
  1. 5 0
      source/time/Date.cpp
  2. 2 1
      source/time/Date.hpp
  3. 10 1
      test/cases/time/DateTest.cpp

+ 5 - 0
source/time/Date.cpp

@@ -22,6 +22,11 @@ ls_std::Date & ls_std::Date::operator+(int _value) {
   return *this;
   return *this;
 }
 }
 
 
+ls_std::Date & ls_std::Date::operator-(int _value) {
+  this->timestamp -= (_value * 86400);
+  return *this;
+}
+
 bool ls_std::Date::after(const Date& _foreignDate) const {
 bool ls_std::Date::after(const Date& _foreignDate) const {
   return this->timestamp > _foreignDate.getTime();
   return this->timestamp > _foreignDate.getTime();
 }
 }

+ 2 - 1
source/time/Date.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-14
  * Created:         2020-08-14
- * Changed:         2020-08-16
+ * Changed:         2020-08-21
  *
  *
  * */
  * */
 
 
@@ -23,6 +23,7 @@ namespace ls_std {
       // arithmetic operators
       // arithmetic operators
 
 
       Date& operator+(int _value);
       Date& operator+(int _value);
+      Date& operator-(int _value);
 
 
       // additional functionality
       // additional functionality
 
 

+ 10 - 1
test/cases/time/DateTest.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-14
  * Created:         2020-08-14
- * Changed:         2020-08-14
+ * Changed:         2020-08-21
  *
  *
  * */
  * */
 
 
@@ -33,6 +33,15 @@ namespace {
     ASSERT_EQ(timestamp + 86400, date.getTime());
     ASSERT_EQ(timestamp + 86400, date.getTime());
   }
   }
 
 
+  TEST_F(DateTest, operatorSub)
+  {
+    ls_std::Date date {};
+    time_t timestamp = date.getTime();
+
+    date = date - 1;
+    ASSERT_EQ(timestamp - 86400, date.getTime());
+  }
+
   // additional functionality
   // additional functionality
 
 
   TEST_F(DateTest, after)
   TEST_F(DateTest, after)