SystemTime.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-03-15
  6. * Changed: 2023-03-31
  7. *
  8. * */
  9. #include <ls-std/core/Class.hpp>
  10. #include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
  11. #include <ls-std/time/system-time/PosixClock.hpp>
  12. #include <ls-std/time/system-time/SystemTime.hpp>
  13. #include <ls-std/time/system-time/SystemTimeParameter.hpp>
  14. #include <memory>
  15. using ls::std::core::Class;
  16. using ls::std::core::NullPointerArgumentEvaluator;
  17. using ls::std::time::DateParameter;
  18. using ls::std::time::PosixClock;
  19. using ls::std::time::SystemTime;
  20. using ls::std::time::SystemTimeParameter;
  21. using ls::std::time::type::UnixTimestamp;
  22. using std::make_shared;
  23. using std::shared_ptr;
  24. SystemTime::SystemTime(const shared_ptr<SystemTimeParameter> &_parameter) : SystemTime()
  25. {
  26. NullPointerArgumentEvaluator{_parameter}.evaluate();
  27. this->parameter = _parameter;
  28. }
  29. SystemTime::SystemTime() : Class("SystemTime")
  30. {
  31. this->_generateParameter();
  32. }
  33. SystemTime::~SystemTime() noexcept = default;
  34. bool SystemTime::set(const DateParameter &_dateParameter)
  35. {
  36. return this->parameter->getClock()->setTime(_dateParameter);
  37. }
  38. void SystemTime::_generateParameter()
  39. {
  40. this->parameter = make_shared<SystemTimeParameter>();
  41. #if defined(unix) || defined(__APPLE__)
  42. this->parameter->setClock(make_shared<PosixClock>());
  43. #endif
  44. }