DateParameterMapper.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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
  34. #ifdef _WIN32
  35. SYSTEMTIME DateParameterMapper::toWindowsSystemTime(const DateParameter &_dateParameter)
  36. {
  37. SYSTEMTIME systemTime{};
  38. systemTime.wYear = _dateParameter.getYear();
  39. systemTime.wMonth = _dateParameter.getMonth();
  40. systemTime.wDayOfWeek = 0;
  41. systemTime.wDay = _dateParameter.getDay();
  42. systemTime.wHour = _dateParameter.getHour();
  43. systemTime.wMinute = _dateParameter.getMinute();
  44. systemTime.wSecond = _dateParameter.getSecond();
  45. systemTime.wMilliseconds = 0;
  46. return systemTime;
  47. }
  48. #endif