DateParameterMapper.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-03-31
  6. * Changed: 2023-05-17
  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. struct tm timeInfo
  24. {
  25. };
  26. localtime_r(&rawTime, &timeInfo);
  27. timeInfo.tm_year = _dateParameter.getYear() - 1900;
  28. timeInfo.tm_mon = _dateParameter.getMonth() - 1;
  29. timeInfo.tm_mday = _dateParameter.getDay();
  30. timeInfo.tm_hour = _dateParameter.getHour();
  31. timeInfo.tm_min = _dateParameter.getMinute();
  32. timeInfo.tm_sec = _dateParameter.getSecond();
  33. timeInfo.tm_isdst = -1;
  34. return (UnixTimestamp) mktime(&timeInfo);
  35. }
  36. #endif
  37. #ifdef _WIN32
  38. SYSTEMTIME DateParameterMapper::toWindowsSystemTime(const DateParameter &_dateParameter)
  39. {
  40. SYSTEMTIME systemTime{};
  41. systemTime.wYear = _dateParameter.getYear();
  42. systemTime.wMonth = _dateParameter.getMonth();
  43. systemTime.wDayOfWeek = 0;
  44. systemTime.wDay = _dateParameter.getDay();
  45. systemTime.wHour = _dateParameter.getHour();
  46. systemTime.wMinute = _dateParameter.getMinute();
  47. systemTime.wSecond = _dateParameter.getSecond();
  48. systemTime.wMilliseconds = 0;
  49. return systemTime;
  50. }
  51. #endif