DateParameterMapper.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-03-31
  6. * Changed: 2023-03-31
  7. *
  8. * */
  9. #include <ctime>
  10. #include <ls-std/time/common/DateParameterMapper.hpp>
  11. using ls::std::time::DateParameter;
  12. using ls::std::time::DateParameterMapper;
  13. using ls::std::time::type::UnixTimestamp;
  14. DateParameterMapper::DateParameterMapper() = default;
  15. DateParameterMapper::~DateParameterMapper() = default;
  16. UnixTimestamp DateParameterMapper::toUnixTimestamp(const DateParameter &_dateParameter)
  17. {
  18. time_t rawTime{};
  19. ::time(&rawTime);
  20. tm *timeInfo = localtime(&rawTime);
  21. timeInfo->tm_year = _dateParameter.getYear() - 1900;
  22. timeInfo->tm_mon = _dateParameter.getMonth() - 1;
  23. timeInfo->tm_mday = _dateParameter.getDay();
  24. timeInfo->tm_hour = _dateParameter.getHour();
  25. timeInfo->tm_min = _dateParameter.getMinute();
  26. timeInfo->tm_sec = _dateParameter.getSecond();
  27. timeInfo->tm_isdst = -1;
  28. return (UnixTimestamp) mktime(timeInfo);
  29. }