123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- /*
- * Author: Patrick-Christopher Mattulat
- * Company: Lynar Studios
- * E-Mail: webmaster@lynarstudios.com
- * Created: 2023-03-31
- * Changed: 2024-05-31
- *
- * */
- #if defined(unix) || defined(__APPLE__)
- #include <ctime>
- #endif
- #include <ls-std/time/common/DateParameterMapper.hpp>
- using ls::std::time::DateParameter;
- using ls::std::time::DateParameterMapper;
- using ls::std::time::type::UnixTimestamp;
- DateParameterMapper::DateParameterMapper() = default;
- DateParameterMapper::~DateParameterMapper() = default;
- #if defined(unix) || defined(__APPLE__)
- UnixTimestamp DateParameterMapper::toUnixTimestamp(const DateParameter &_dateParameter)
- {
- time_t rawTime{};
- ::time(&rawTime);
- tm timeInfo
- {
- };
- localtime_r(&rawTime, &timeInfo);
- timeInfo.tm_year = _dateParameter.getYear() - 1900;
- timeInfo.tm_mon = _dateParameter.getMonth() - 1;
- timeInfo.tm_mday = _dateParameter.getDay();
- timeInfo.tm_hour = _dateParameter.getHour();
- timeInfo.tm_min = _dateParameter.getMinute();
- timeInfo.tm_sec = _dateParameter.getSecond();
- timeInfo.tm_isdst = -1;
- return static_cast<UnixTimestamp>(mktime(&timeInfo));
- }
- #endif
- #ifdef _WIN32
- SYSTEMTIME DateParameterMapper::toWindowsSystemTime(const DateParameter &_dateParameter)
- {
- SYSTEMTIME systemTime{};
- systemTime.wYear = _dateParameter.getYear();
- systemTime.wMonth = _dateParameter.getMonth();
- systemTime.wDayOfWeek = 0;
- systemTime.wDay = _dateParameter.getDay();
- systemTime.wHour = _dateParameter.getHour();
- systemTime.wMinute = _dateParameter.getMinute();
- systemTime.wSecond = _dateParameter.getSecond();
- systemTime.wMilliseconds = 0;
- return systemTime;
- }
- #endif
|