Преглед на файлове

Add DateParameter class

This class can be passed to convert a human-readable date into
any other time based format.
Patrick-Christopher Mattulat преди 1 година
родител
ревизия
61b4bfdfb0

+ 2 - 0
CMakeLists.txt

@@ -255,6 +255,7 @@ set(SOURCE_FILES_IO
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/io/StorableFile.cpp)
 
 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/system-time/PosixClock.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/time/system-time/SystemTime.cpp
@@ -380,6 +381,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/DateParameterTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/time/system-time/SystemTimeParameterTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/time/system-time/SystemTimeTest.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/time/DateTest.cpp

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

@@ -3,19 +3,23 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2022-05-16
- * Changed:         2023-03-16
+ * Changed:         2023-03-29
  *
  * */
 
 #ifndef LS_STD_LS_STD_TIME_HPP
 #define LS_STD_LS_STD_TIME_HPP
 
+#include <ls-std/time/common/DateParameter.hpp>
+
 #include <ls-std/time/system-time/IPosixClock.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>
+
 #include <ls-std/time/Date.hpp>
 
 #endif

+ 54 - 0
include/ls-std/time/common/DateParameter.hpp

@@ -0,0 +1,54 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-03-29
+* Changed:         2023-03-29
+*
+* */
+
+#ifndef LS_STD_DATE_PARAMETER_HPP
+#define LS_STD_DATE_PARAMETER_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 DateParameter
+  {
+    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();
+      ~DateParameter();
+
+      [[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);
+      void setYear(ls::std::time::type::Year _year);
+
+    private:
+
+      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{};
+      ls::std::time::type::Year year{};
+  };
+}
+
+#endif

+ 24 - 0
include/ls-std/time/type/DateParameterTypes.hpp

@@ -0,0 +1,24 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-03-29
+* Changed:         2023-03-29
+*
+* */
+
+#ifndef LS_STD_DATE_PARAMETER_TYPES_HPP
+#define LS_STD_DATE_PARAMETER_TYPES_HPP
+
+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;
+}
+
+#endif

+ 96 - 0
source/ls-std/time/common/DateParameter.cpp

@@ -0,0 +1,96 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-03-29
+* Changed:         2023-03-29
+*
+* */
+
+#include <ls-std/time/common/DateParameter.hpp>
+
+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() = default;
+
+DateParameter::~DateParameter() = default;
+
+Day DateParameter::getDay() const
+{
+  return this->day;
+}
+
+Hour DateParameter::getHour() const
+{
+  return this->hour;
+}
+
+Millisecond DateParameter::getMillisecond() const
+{
+  return this->millisecond;
+}
+
+Minute DateParameter::getMinute() const
+{
+  return this->minute;
+}
+
+Month DateParameter::getMonth() const
+{
+  return this->month;
+}
+
+Second DateParameter::getSecond() const
+{
+  return this->second;
+}
+
+Year DateParameter::getYear() const
+{
+  return this->year;
+}
+
+void DateParameter::setDay(Day _day)
+{
+  this->day = _day;
+}
+
+void DateParameter::setHour(Hour _hour)
+{
+  this->hour = _hour;
+}
+
+void DateParameter::setMillisecond(Millisecond _millisecond)
+{
+  this->millisecond = _millisecond;
+}
+
+void DateParameter::setMinute(Minute _minute)
+{
+  this->minute = _minute;
+}
+
+void DateParameter::setMonth(Month _month)
+{
+  this->month = _month;
+}
+
+void DateParameter::setSecond(Second _second)
+{
+  this->second = _second;
+}
+
+void DateParameter::setYear(Year _year)
+{
+  this->year = _year;
+}

+ 136 - 0
test/cases/time/common/DateParameterTest.cpp

@@ -0,0 +1,136 @@
+/*
+* Author:          Patrick-Christopher Mattulat
+* Company:         Lynar Studios
+* E-Mail:          webmaster@lynarstudios.com
+* Created:         2023-03-29
+* Changed:         2023-03-29
+*
+* */
+
+#include <gtest/gtest.h>
+#include <ls-std/ls-std-time.hpp>
+
+using ls::std::time::DateParameter;
+using testing::Test;
+
+namespace
+{
+  class DateParameterTest : public Test
+  {
+    public:
+
+      DateParameterTest() = default;
+      ~DateParameterTest() override = default;
+  };
+
+  TEST_F(DateParameterTest, constructor)
+  {
+    DateParameter parameter{1989, 6, 1, 10, 52, 13, 102};
+
+    ASSERT_EQ(1989, parameter.getYear());
+    ASSERT_EQ(6, parameter.getMonth());
+    ASSERT_EQ(1, parameter.getDay());
+    ASSERT_EQ(10, parameter.getHour());
+    ASSERT_EQ(52, parameter.getMinute());
+    ASSERT_EQ(13, parameter.getSecond());
+    ASSERT_EQ(102, parameter.getMillisecond());
+  }
+
+  TEST_F(DateParameterTest, getDay)
+  {
+    DateParameter parameter{};
+    ASSERT_EQ(0, parameter.getDay());
+  }
+
+  TEST_F(DateParameterTest, getHour)
+  {
+    DateParameter parameter{};
+    ASSERT_EQ(0, parameter.getHour());
+  }
+
+  TEST_F(DateParameterTest, getMillisecond)
+  {
+    DateParameter parameter{};
+    ASSERT_EQ(0, parameter.getMillisecond());
+  }
+
+  TEST_F(DateParameterTest, getMinute)
+  {
+    DateParameter parameter{};
+    ASSERT_EQ(0, parameter.getMinute());
+  }
+
+  TEST_F(DateParameterTest, getMonth)
+  {
+    DateParameter parameter{};
+    ASSERT_EQ(0, parameter.getMonth());
+  }
+
+  TEST_F(DateParameterTest, getSecond)
+  {
+    DateParameter parameter{};
+    ASSERT_EQ(0, parameter.getSecond());
+  }
+
+  TEST_F(DateParameterTest, getYear)
+  {
+    DateParameter parameter{};
+    ASSERT_EQ(0, parameter.getYear());
+  }
+
+  TEST_F(DateParameterTest, setDay)
+  {
+    DateParameter parameter{};
+    parameter.setDay(1);
+
+    ASSERT_EQ(1, parameter.getDay());
+  }
+
+  TEST_F(DateParameterTest, setHour)
+  {
+    DateParameter parameter{};
+    parameter.setHour(10);
+
+    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{};
+    parameter.setMinute(52);
+
+    ASSERT_EQ(52, parameter.getMinute());
+  }
+
+  TEST_F(DateParameterTest, setMonth)
+  {
+    DateParameter parameter{};
+    parameter.setMonth(6);
+
+    ASSERT_EQ(6, parameter.getMonth());
+  }
+
+  TEST_F(DateParameterTest, setSecond)
+  {
+    DateParameter parameter{};
+    parameter.setSecond(13);
+
+    ASSERT_EQ(13, parameter.getSecond());
+  }
+
+  TEST_F(DateParameterTest, setYear)
+  {
+    DateParameter parameter{};
+    parameter.setYear(1989);
+
+    ASSERT_EQ(1989, parameter.getYear());
+  }
+}