PosixClock.cpp 797 B

12345678910111213141516171819202122232425262728
  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 <ctime>
  10. #include <ls-std/time/common/DateParameterMapper.hpp>
  11. #include <ls-std/time/system-time/PosixClock.hpp>
  12. using ls::std::time::DateParameter;
  13. using ls::std::time::DateParameterMapper;
  14. using ls::std::time::PosixClock;
  15. using ls::std::time::type::UnixTimestamp;
  16. PosixClock::PosixClock() = default;
  17. PosixClock::~PosixClock() noexcept = default;
  18. bool PosixClock::setTime(const DateParameter &_dateParameter)
  19. {
  20. UnixTimestamp timestamp = DateParameterMapper::toUnixTimestamp(_dateParameter);
  21. timespec timespec{timestamp, 0};
  22. return clock_settime(CLOCK_REALTIME, &timespec) == 0;
  23. }