Sfoglia il codice sorgente

Replace set method signature of SystemTime class

Instead of passing UNIX timestamp to set method of SectionTime
class, which only works for POSIX systems, a model class is
being passed, which takes the elementary date parameter, like
day, month, hour ect.
Patrick-Christopher Mattulat 1 anno fa
parent
commit
32f0c2c416

+ 4 - 2
CMakeLists.txt

@@ -84,7 +84,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
 # Compiler Support
 ##########################################################
 
-if(${LS_STD_BUILD_WITH_SUPPORTED_COMPILER})
+if (${LS_STD_BUILD_WITH_SUPPORTED_COMPILER})
     message("${PROJECT_NAME}: build with compiler support...")
 
     # define supported compilers
@@ -256,7 +256,8 @@ set(SOURCE_FILES_IO
 
 set(SOURCE_FILES_TIME
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/time/common/DateParameter.cpp
-        ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/time/system-time/IPosixClock.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/time/common/DateParameterMapper.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/time/system-time/IClock.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/time/system-time/PosixClock.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/time/system-time/SystemTime.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/time/system-time/SystemTimeParameter.cpp
@@ -381,6 +382,7 @@ if (${LS_STD_BUILD_WITH_TESTS})
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/JsonTest.cpp)
 
     set(UNIT_TEST_FILES_TIME
+            ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/time/common/DateParameterMapperTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/time/common/DateParameterTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/time/system-time/SystemTimeParameterTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/time/system-time/SystemTimeTest.cpp

+ 5 - 3
include/ls-std/ls-std-time.hpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2022-05-16
- * Changed:         2023-03-29
+ * Changed:         2023-03-31
  *
  * */
 
@@ -11,12 +11,14 @@
 #define LS_STD_LS_STD_TIME_HPP
 
 #include <ls-std/time/common/DateParameter.hpp>
+#include <ls-std/time/common/DateParameterMapper.hpp>
 
-#include <ls-std/time/system-time/IPosixClock.hpp>
+#include <ls-std/time/system-time/jni/com_lynarstudios_ls_std_time_systemtime_SystemTimeJni.h>
+
+#include <ls-std/time/system-time/IClock.hpp>
 #include <ls-std/time/system-time/PosixClock.hpp>
 #include <ls-std/time/system-time/SystemTime.hpp>
 #include <ls-std/time/system-time/SystemTimeParameter.hpp>
-#include <ls-std/time/system-time/jni/com_lynarstudios_ls_std_time_systemtime_SystemTimeJni.h>
 
 #include <ls-std/time/type/DateParameterTypes.hpp>
 

+ 4 - 5
include/ls-std/time/common/DateParameter.hpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-29
-* Changed:         2023-03-29
+* Changed:         2023-03-31
 *
 * */
 
@@ -20,20 +20,20 @@ namespace ls::std::time
   {
     public:
 
-      DateParameter(ls::std::time::type::Year _year, ls::std::time::type::Month _month, ls::std::time::type::Day _day, ls::std::time::type::Hour _hour, ls::std::time::type::Minute _minute, ls::std::time::type::Second _second, ls::std::time::type::Millisecond _millisecond);
+      DateParameter(ls::std::time::type::Year _year, ls::std::time::type::Month _month, ls::std::time::type::Day _day, ls::std::time::type::Hour _hour, ls::std::time::type::Minute _minute, ls::std::time::type::Second _second);
       DateParameter();
       ~DateParameter();
 
+      bool operator==(const ls::std::time::DateParameter &_dateParameter) const;
+
       [[nodiscard]] ls::std::time::type::Day getDay() const;
       [[nodiscard]] ls::std::time::type::Hour getHour() const;
-      [[nodiscard]] ls::std::time::type::Millisecond getMillisecond() const;
       [[nodiscard]] ls::std::time::type::Minute getMinute() const;
       [[nodiscard]] ls::std::time::type::Month getMonth() const;
       [[nodiscard]] ls::std::time::type::Second getSecond() const;
       [[nodiscard]] ls::std::time::type::Year getYear() const;
       void setDay(ls::std::time::type::Day _day);
       void setHour(ls::std::time::type::Hour _hour);
-      void setMillisecond(ls::std::time::type::Millisecond _millisecond);
       void setMinute(ls::std::time::type::Minute _minute);
       void setMonth(ls::std::time::type::Month _month);
       void setSecond(ls::std::time::type::Second _second);
@@ -43,7 +43,6 @@ namespace ls::std::time
 
       ls::std::time::type::Day day{};
       ls::std::time::type::Hour hour{};
-      ls::std::time::type::Millisecond millisecond{};
       ls::std::time::type::Minute minute{};
       ls::std::time::type::Month month{};
       ls::std::time::type::Second second{};

+ 30 - 0
include/ls-std/time/common/DateParameterMapper.hpp

@@ -0,0 +1,30 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-03-31
+* Changed:         2023-03-31
+*
+* */
+
+#ifndef LS_STD_DATE_PARAMETER_MAPPER_HPP
+#define LS_STD_DATE_PARAMETER_MAPPER_HPP
+
+#include "DateParameter.hpp"
+#include <ls-std/os/dynamic-goal.hpp>
+#include <ls-std/time/type/DateParameterTypes.hpp>
+
+namespace ls::std::time
+{
+  class LS_STD_DYNAMIC_GOAL DateParameterMapper
+  {
+    public:
+
+      DateParameterMapper();
+      ~DateParameterMapper();
+
+      [[nodiscard]] static ls::std::time::type::UnixTimestamp toUnixTimestamp(const ls::std::time::DateParameter &_dateParameter);
+  };
+}
+
+#endif

+ 29 - 0
include/ls-std/time/system-time/IClock.hpp

@@ -0,0 +1,29 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-03-31
+* Changed:         2023-03-31
+*
+* */
+
+#ifndef LS_STD_I_CLOCK_HPP
+#define LS_STD_I_CLOCK_HPP
+
+#include <ls-std/os/dynamic-goal.hpp>
+#include <ls-std/time/common/DateParameter.hpp>
+
+namespace ls::std::time
+{
+  class LS_STD_DYNAMIC_GOAL IClock
+  {
+    public:
+
+      IClock();
+      virtual ~IClock();
+
+      virtual bool setTime(const ls::std::time::DateParameter &_dateParameter) = 0;
+  };
+}
+
+#endif

+ 0 - 29
include/ls-std/time/system-time/IPosixClock.hpp

@@ -1,29 +0,0 @@
-/*
-* Author:          Patrick-Christopher Mattulat
-* Company:         Lynar Studios
-* E-Mail:          webmaster@lynarstudios.com
-* Created:         2023-03-15
-* Changed:         2023-03-15
-*
-* */
-
-#ifndef LS_STD_I_POSIX_CLOCK_HPP
-#define LS_STD_I_POSIX_CLOCK_HPP
-
-#include <cstdint>
-#include <ls-std/os/dynamic-goal.hpp>
-
-namespace ls::std::time
-{
-  class LS_STD_DYNAMIC_GOAL IPosixClock
-  {
-    public:
-
-      IPosixClock();
-      virtual ~IPosixClock();
-
-      virtual bool setTime(uint32_t _timeStamp) = 0;
-  };
-}
-
-#endif

+ 5 - 4
include/ls-std/time/system-time/PosixClock.hpp

@@ -3,27 +3,28 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-15
-* Changed:         2023-03-15
+* Changed:         2023-03-31
 *
 * */
 
 #ifndef LS_STD_POSIX_CLOCK_HPP
 #define LS_STD_POSIX_CLOCK_HPP
 
-#include "IPosixClock.hpp"
+#include "IClock.hpp"
 #include <cstdint>
 #include <ls-std/os/dynamic-goal.hpp>
+#include <ls-std/time/type/DateParameterTypes.hpp>
 
 namespace ls::std::time
 {
-  class LS_STD_DYNAMIC_GOAL PosixClock : public ls::std::time::IPosixClock
+  class LS_STD_DYNAMIC_GOAL PosixClock : public ls::std::time::IClock
   {
     public:
 
       PosixClock();
       ~PosixClock() noexcept override;
 
-      [[nodiscard]] bool setTime(uint32_t _timeStamp) override;
+      [[nodiscard]] bool setTime(const ls::std::time::DateParameter &_dateParameter) override;
   };
 }
 

+ 4 - 2
include/ls-std/time/system-time/SystemTime.hpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-07
-* Changed:         2023-03-15
+* Changed:         2023-03-31
 *
 * */
 
@@ -14,6 +14,8 @@
 #include <cstdint>
 #include <ls-std/core/Class.hpp>
 #include <ls-std/os/dynamic-goal.hpp>
+#include <ls-std/time/common/DateParameter.hpp>
+#include <ls-std/time/type/DateParameterTypes.hpp>
 #include <memory>
 
 namespace ls::std::time
@@ -26,7 +28,7 @@ namespace ls::std::time
       SystemTime();
       ~SystemTime() noexcept override;
 
-      [[nodiscard]] bool set(uint32_t _timeStamp);
+      [[nodiscard]] bool set(const ls::std::time::DateParameter &_dateParameter);
 
     private:
 

+ 5 - 5
include/ls-std/time/system-time/SystemTimeParameter.hpp

@@ -3,14 +3,14 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-15
-* Changed:         2023-03-15
+* Changed:         2023-03-31
 *
 * */
 
 #ifndef LS_STD_SYSTEM_TIME_PARAMETER_HPP
 #define LS_STD_SYSTEM_TIME_PARAMETER_HPP
 
-#include "IPosixClock.hpp"
+#include "IClock.hpp"
 #include <ls-std/os/dynamic-goal.hpp>
 #include <memory>
 
@@ -23,12 +23,12 @@ namespace ls::std::time
       SystemTimeParameter();
       ~SystemTimeParameter();
 
-      [[nodiscard]] ::std::shared_ptr<ls::std::time::IPosixClock> getPosixClock();
-      void setPosixClock(const ::std::shared_ptr<ls::std::time::IPosixClock> &_posixClock);
+      [[nodiscard]] ::std::shared_ptr<ls::std::time::IClock> getClock();
+      void setClock(const ::std::shared_ptr<ls::std::time::IClock> &_clock);
 
     private:
 
-      ::std::shared_ptr<ls::std::time::IPosixClock> posixClock{};
+      ::std::shared_ptr<ls::std::time::IClock> clock{};
   };
 }
 

+ 3 - 3
include/ls-std/time/type/DateParameterTypes.hpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-29
-* Changed:         2023-03-29
+* Changed:         2023-03-31
 *
 * */
 
@@ -14,11 +14,11 @@ namespace ls::std::time::type
 {
   using Day = uint8_t;
   using Hour = uint8_t;
-  using Millisecond = uint16_t;
   using Minute = uint8_t;
   using Month = uint8_t;
   using Second = uint8_t;
-  using Year = uint32_t;
+  using UnixTimestamp = uint32_t;
+  using Year = int;
 }
 
 #endif

+ 7 - 13
source/ls-std/time/common/DateParameter.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-29
-* Changed:         2023-03-29
+* Changed:         2023-03-31
 *
 * */
 
@@ -12,19 +12,23 @@
 using ls::std::time::DateParameter;
 using ls::std::time::type::Day;
 using ls::std::time::type::Hour;
-using ls::std::time::type::Millisecond;
 using ls::std::time::type::Minute;
 using ls::std::time::type::Month;
 using ls::std::time::type::Second;
 using ls::std::time::type::Year;
 
-DateParameter::DateParameter(Year _year, Month _month, Day _day, Hour _hour, Minute _minute, Second _second, Millisecond _millisecond) : year(_year), month(_month), day(_day), hour(_hour), minute(_minute), second(_second), millisecond(_millisecond)
+DateParameter::DateParameter(Year _year, Month _month, Day _day, Hour _hour, Minute _minute, Second _second) : year(_year), month(_month), day(_day), hour(_hour), minute(_minute), second(_second)
 {}
 
 DateParameter::DateParameter() = default;
 
 DateParameter::~DateParameter() = default;
 
+bool DateParameter::operator==(const DateParameter &_dateParameter) const
+{
+  return this->day == _dateParameter.getDay() && this->hour == _dateParameter.getHour() && this->minute == _dateParameter.getMinute() && this->month == _dateParameter.getMonth() && this->second == _dateParameter.getSecond() && this->year == _dateParameter.getYear();
+}
+
 Day DateParameter::getDay() const
 {
   return this->day;
@@ -35,11 +39,6 @@ Hour DateParameter::getHour() const
   return this->hour;
 }
 
-Millisecond DateParameter::getMillisecond() const
-{
-  return this->millisecond;
-}
-
 Minute DateParameter::getMinute() const
 {
   return this->minute;
@@ -70,11 +69,6 @@ void DateParameter::setHour(Hour _hour)
   this->hour = _hour;
 }
 
-void DateParameter::setMillisecond(Millisecond _millisecond)
-{
-  this->millisecond = _millisecond;
-}
-
 void DateParameter::setMinute(Minute _minute)
 {
   this->minute = _minute;

+ 35 - 0
source/ls-std/time/common/DateParameterMapper.cpp

@@ -0,0 +1,35 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-03-31
+* Changed:         2023-03-31
+*
+* */
+
+#include <ctime>
+#include <ls-std/time/common/DateParameterMapper.hpp>
+
+using ls::std::time::DateParameter;
+using ls::std::time::DateParameterMapper;
+using ls::std::time::type::UnixTimestamp;
+
+DateParameterMapper::DateParameterMapper() = default;
+
+DateParameterMapper::~DateParameterMapper() = default;
+
+UnixTimestamp DateParameterMapper::toUnixTimestamp(const DateParameter &_dateParameter)
+{
+  time_t rawTime{};
+  ::time(&rawTime);
+  tm *timeInfo = localtime(&rawTime);
+  timeInfo->tm_year = _dateParameter.getYear() - 1900;
+  timeInfo->tm_mon = _dateParameter.getMonth() - 1;
+  timeInfo->tm_mday = _dateParameter.getDay();
+  timeInfo->tm_hour = _dateParameter.getHour();
+  timeInfo->tm_min = _dateParameter.getMinute();
+  timeInfo->tm_sec = _dateParameter.getSecond();
+  timeInfo->tm_isdst = -1;
+
+  return (UnixTimestamp) mktime(timeInfo);
+}

+ 16 - 0
source/ls-std/time/system-time/IClock.cpp

@@ -0,0 +1,16 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-03-31
+* Changed:         2023-03-31
+*
+* */
+
+#include <ls-std/time/system-time/IClock.hpp>
+
+using ls::std::time::IClock;
+
+IClock::IClock() = default;
+
+IClock::~IClock() = default;

+ 0 - 16
source/ls-std/time/system-time/IPosixClock.cpp

@@ -1,16 +0,0 @@
-/*
-* Author:          Patrick-Christopher Mattulat
-* Company:         Lynar Studios
-* E-Mail:          webmaster@lynarstudios.com
-* Created:         2023-03-15
-* Changed:         2023-03-15
-*
-* */
-
-#include <ls-std/time/system-time/IPosixClock.hpp>
-
-using ls::std::time::IPosixClock;
-
-IPosixClock::IPosixClock() = default;
-
-IPosixClock::~IPosixClock() = default;

+ 8 - 3
source/ls-std/time/system-time/PosixClock.cpp

@@ -3,21 +3,26 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-15
-* Changed:         2023-03-15
+* Changed:         2023-03-31
 *
 * */
 
 #include <ctime>
+#include <ls-std/time/common/DateParameterMapper.hpp>
 #include <ls-std/time/system-time/PosixClock.hpp>
 
+using ls::std::time::DateParameter;
+using ls::std::time::DateParameterMapper;
 using ls::std::time::PosixClock;
+using ls::std::time::type::UnixTimestamp;
 
 PosixClock::PosixClock() = default;
 
 PosixClock::~PosixClock() noexcept = default;
 
-bool PosixClock::setTime(uint32_t _timeStamp)
+bool PosixClock::setTime(const DateParameter &_dateParameter)
 {
-  timespec timespec{_timeStamp, 0};
+  UnixTimestamp timestamp = DateParameterMapper::toUnixTimestamp(_dateParameter);
+  timespec timespec{timestamp, 0};
   return clock_settime(CLOCK_REALTIME, &timespec) == 0;
 }

+ 6 - 4
source/ls-std/time/system-time/SystemTime.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-15
-* Changed:         2023-03-15
+* Changed:         2023-03-31
 *
 * */
 
@@ -16,9 +16,11 @@
 
 using ls::std::core::Class;
 using ls::std::core::NullPointerArgumentEvaluator;
+using ls::std::time::DateParameter;
 using ls::std::time::PosixClock;
 using ls::std::time::SystemTime;
 using ls::std::time::SystemTimeParameter;
+using ls::std::time::type::UnixTimestamp;
 using std::make_shared;
 using std::shared_ptr;
 
@@ -35,13 +37,13 @@ SystemTime::SystemTime() : Class("SystemTime")
 
 SystemTime::~SystemTime() noexcept = default;
 
-bool SystemTime::set(uint32_t _timeStamp)
+bool SystemTime::set(const DateParameter &_dateParameter)
 {
-  return this->parameter->getPosixClock()->setTime(_timeStamp);
+  return this->parameter->getClock()->setTime(_dateParameter);
 }
 
 void SystemTime::_generateParameter()
 {
   this->parameter = make_shared<SystemTimeParameter>();
-  this->parameter->setPosixClock(make_shared<PosixClock>());
+  this->parameter->setClock(make_shared<PosixClock>());
 }

+ 6 - 7
source/ls-std/time/system-time/SystemTimeParameter.cpp

@@ -3,15 +3,14 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-15
-* Changed:         2023-03-15
+* Changed:         2023-03-31
 *
 * */
 
-#include <ls-std/time/system-time/IPosixClock.hpp>
 #include <ls-std/time/system-time/SystemTimeParameter.hpp>
 #include <memory>
 
-using ls::std::time::IPosixClock;
+using ls::std::time::IClock;
 using ls::std::time::SystemTimeParameter;
 using std::shared_ptr;
 
@@ -19,12 +18,12 @@ SystemTimeParameter::SystemTimeParameter() = default;
 
 SystemTimeParameter::~SystemTimeParameter() = default;
 
-shared_ptr<IPosixClock> SystemTimeParameter::getPosixClock()
+shared_ptr<IClock> SystemTimeParameter::getClock()
 {
-  return this->posixClock;
+  return this->clock;
 }
 
-void SystemTimeParameter::setPosixClock(const shared_ptr<IPosixClock> &_posixClock)
+void SystemTimeParameter::setClock(const shared_ptr<IClock> &_clock)
 {
-  this->posixClock = _posixClock;
+  this->clock = _clock;
 }

+ 3 - 2
source/ls-std/time/system-time/jni/com_lynarstudios_ls_std_time_systemtime_SystemTimeJni.cpp

@@ -3,16 +3,17 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-16
-* Changed:         2023-03-16
+* Changed:         2023-03-31
 *
 * */
 
 #include <ls-std/time/system-time/SystemTime.hpp>
 #include <ls-std/time/system-time/jni/com_lynarstudios_ls_std_time_systemtime_SystemTimeJni.h>
 
+using ls::std::time::DateParameter;
 using ls::std::time::SystemTime;
 
 JNIEXPORT jboolean JNICALL Java_com_lynarstudios_ls_std_time_systemtime_SystemTimeJni_set(JNIEnv *_environment, jobject _object, jlong _long)
 {
-  return SystemTime{}.set(_long);
+  return SystemTime{}.set(DateParameter{});
 }

+ 51 - 0
test/cases/time/common/DateParameterMapperTest.cpp

@@ -0,0 +1,51 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-03-31
+* Changed:         2023-03-31
+*
+* */
+
+#include <gtest/gtest.h>
+#include <ls-std/ls-std-time.hpp>
+#include <utility>
+#include <vector>
+
+using ls::std::time::DateParameter;
+using ls::std::time::DateParameterMapper;
+using ls::std::time::type::UnixTimestamp;
+using std::pair;
+using std::vector;
+using testing::TestWithParam;
+using testing::Values;
+
+namespace
+{
+  class DateParameterMapperTest : public TestWithParam<pair<UnixTimestamp, DateParameter>>
+  {
+    public:
+
+      DateParameterMapperTest() = default;
+      ~DateParameterMapperTest() override = default;
+
+      static vector<pair<UnixTimestamp, DateParameter>> getTestParameterList()
+      {
+        vector<pair<UnixTimestamp, DateParameter>> testParameterList{};
+        testParameterList.emplace_back(656936700, DateParameter{1990, 10, 26, 11, 25, 00});
+        testParameterList.emplace_back(612694320, DateParameter{1989, 6, 1, 10, 52, 00});
+
+        return testParameterList;
+      }
+  };
+
+  TEST_P(DateParameterMapperTest, toUnixTimestamp)
+  {
+    DateParameter dateParameter = GetParam().second;
+    UnixTimestamp timestamp = DateParameterMapper::toUnixTimestamp(dateParameter);
+
+    ASSERT_EQ(GetParam().first, timestamp);
+  }
+
+  INSTANTIATE_TEST_SUITE_P(toUnixTimestamp, DateParameterMapperTest, Values(DateParameterMapperTest::getTestParameterList().at(0), DateParameterMapperTest::getTestParameterList().at(1)));
+}

+ 18 - 17
test/cases/time/common/DateParameterTest.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-29
-* Changed:         2023-03-29
+* Changed:         2023-03-31
 *
 * */
 
@@ -25,7 +25,7 @@ namespace
 
   TEST_F(DateParameterTest, constructor)
   {
-    DateParameter parameter{1989, 6, 1, 10, 52, 13, 102};
+    DateParameter parameter{1989, 6, 1, 10, 52, 13};
 
     ASSERT_EQ(1989, parameter.getYear());
     ASSERT_EQ(6, parameter.getMonth());
@@ -33,7 +33,22 @@ namespace
     ASSERT_EQ(10, parameter.getHour());
     ASSERT_EQ(52, parameter.getMinute());
     ASSERT_EQ(13, parameter.getSecond());
-    ASSERT_EQ(102, parameter.getMillisecond());
+  }
+
+  TEST_F(DateParameterTest, operator_equals)
+  {
+    DateParameter requiredBirthday{1989, 6, 1, 10, 52, 13};
+    DateParameter hisBirthday{1989, 6, 1, 10, 52, 13};
+
+    ASSERT_TRUE(requiredBirthday == hisBirthday);
+  }
+
+  TEST_F(DateParameterTest, operator_equals_not_equals)
+  {
+    DateParameter hisBirthday{1989, 6, 1, 10, 52, 00};
+    DateParameter herBirthday{1990, 10, 26, 11, 25, 00};
+
+    ASSERT_FALSE(herBirthday == hisBirthday);
   }
 
   TEST_F(DateParameterTest, getDay)
@@ -48,12 +63,6 @@ namespace
     ASSERT_EQ(0, parameter.getHour());
   }
 
-  TEST_F(DateParameterTest, getMillisecond)
-  {
-    DateParameter parameter{};
-    ASSERT_EQ(0, parameter.getMillisecond());
-  }
-
   TEST_F(DateParameterTest, getMinute)
   {
     DateParameter parameter{};
@@ -94,14 +103,6 @@ namespace
     ASSERT_EQ(10, parameter.getHour());
   }
 
-  TEST_F(DateParameterTest, setMillisecond)
-  {
-    DateParameter parameter{};
-    parameter.setMillisecond(133);
-
-    ASSERT_EQ(133, parameter.getMillisecond());
-  }
-
   TEST_F(DateParameterTest, setMinute)
   {
     DateParameter parameter{};

+ 8 - 7
test/cases/time/system-time/SystemTimeParameterTest.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-15
-* Changed:         2023-03-15
+* Changed:         2023-03-31
 *
 * */
 
@@ -11,6 +11,7 @@
 #include <ls-std/ls-std-time.hpp>
 #include <memory>
 
+using ls::std::time::IClock;
 using ls::std::time::PosixClock;
 using ls::std::time::SystemTimeParameter;
 using std::make_shared;
@@ -27,17 +28,17 @@ namespace
       ~SystemTimeParameterTest() override = default;
   };
 
-  TEST_F(SystemTimeParameterTest, getPosixClock)
+  TEST_F(SystemTimeParameterTest, getClock)
   {
-    ASSERT_TRUE(SystemTimeParameter{}.getPosixClock() == nullptr);
+    ASSERT_TRUE(SystemTimeParameter{}.getClock() == nullptr);
   }
 
-  TEST_F(SystemTimeParameterTest, setPosixClock)
+  TEST_F(SystemTimeParameterTest, setClock)
   {
     SystemTimeParameter parameter{};
-    shared_ptr<PosixClock> posixClock = make_shared<PosixClock>();
-    parameter.setPosixClock(posixClock);
+    shared_ptr<IClock> posixClock = make_shared<PosixClock>();
+    parameter.setClock(posixClock);
 
-    ASSERT_TRUE(parameter.getPosixClock() == posixClock);
+    ASSERT_TRUE(parameter.getClock() == posixClock);
   }
 }

+ 4 - 4
test/cases/time/system-time/SystemTimeTest.cpp

@@ -3,11 +3,10 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-15
-* Changed:         2023-03-15
+* Changed:         2023-03-31
 *
 * */
 
-#include <cstdint>
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 #include <ls-std-time-test.hpp>
@@ -16,6 +15,7 @@
 #include <memory>
 
 using ls::std::core::IllegalArgumentException;
+using ls::std::time::DateParameter;
 using ls::std::time::SystemTime;
 using ls::std::time::SystemTimeParameter;
 using std::make_shared;
@@ -60,8 +60,8 @@ namespace
   {
     shared_ptr<SystemTimeParameter> parameter = make_shared<SystemTimeParameter>();
     shared_ptr<MockPosixClock> posixClock = make_shared<MockPosixClock>();
-    parameter->setPosixClock(posixClock);
-    uint32_t birthday = 612694333;
+    parameter->setClock(posixClock);
+    DateParameter birthday = DateParameter(1990, 10, 26, 11, 25, 00);
 
     EXPECT_CALL(*posixClock, setTime(birthday)).Times(AtLeast(1));
     ON_CALL(*posixClock, setTime(birthday)).WillByDefault(Return(true));

+ 5 - 4
test/classes/time/system-time/MockPosixClock.hpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-03-15
-* Changed:         2023-03-15
+* Changed:         2023-03-31
 *
 * */
 
@@ -11,18 +11,19 @@
 #define LS_STD_MOCK_POSIX_CLOCK_HPP
 
 #include <gmock/gmock.h>
-#include <ls-std/time/system-time/IPosixClock.hpp>
+#include <ls-std/time/common/DateParameter.hpp>
+#include <ls-std/time/system-time/IClock.hpp>
 
 namespace test::time
 {
-  class MockPosixClock : public ls::std::time::IPosixClock
+  class MockPosixClock : public ls::std::time::IClock
   {
     public:
 
       MockPosixClock();
       ~MockPosixClock() noexcept override;
 
-      MOCK_METHOD(bool, setTime, (uint32_t _timeStamp), (override));
+      MOCK_METHOD(bool, setTime, (const ls::std::time::DateParameter &_dateParameter), (override));
   };
 }