DateParameterMapper.cpp 1.1 KB

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