mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 23:10:05 +00:00
49 lines
1.2 KiB
C++
49 lines
1.2 KiB
C++
// Enable chrono formatters
|
|
#ifndef __cpp_lib_format
|
|
# define __cpp_lib_format 202110L
|
|
#endif
|
|
|
|
#include <scwx/util/time.hpp>
|
|
|
|
namespace scwx
|
|
{
|
|
namespace util
|
|
{
|
|
|
|
std::chrono::system_clock::time_point TimePoint(uint16_t modifiedJulianDate,
|
|
uint32_t milliseconds)
|
|
{
|
|
using namespace std::chrono;
|
|
using sys_days = time_point<system_clock, days>;
|
|
constexpr auto epoch = sys_days {1969y / December / 31d};
|
|
|
|
return epoch + (modifiedJulianDate * 24h) +
|
|
std::chrono::milliseconds {milliseconds};
|
|
}
|
|
|
|
std::string TimeString(std::chrono::system_clock::time_point time,
|
|
const std::chrono::time_zone* timeZone,
|
|
bool epochValid)
|
|
{
|
|
using namespace std::chrono;
|
|
auto timeInSeconds = time_point_cast<seconds>(time);
|
|
std::ostringstream os;
|
|
|
|
if (epochValid || time.time_since_epoch().count() != 0)
|
|
{
|
|
if (timeZone != nullptr)
|
|
{
|
|
zoned_time zt = {current_zone(), timeInSeconds};
|
|
os << zt;
|
|
}
|
|
else
|
|
{
|
|
os << timeInSeconds;
|
|
}
|
|
}
|
|
|
|
return os.str();
|
|
}
|
|
|
|
} // namespace util
|
|
} // namespace scwx
|