2015-08-17 05:26:58 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
2016-10-09 21:41:23 +00:00
|
|
|
#include <time.h>
|
2015-08-17 05:26:58 +00:00
|
|
|
|
|
|
|
#include "CBasics.hpp"
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
namespace urde
|
2015-08-17 22:05:00 +00:00
|
|
|
{
|
|
|
|
|
2015-08-17 05:26:58 +00:00
|
|
|
void CBasics::Init()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* CBasics::Stringize(const char* fmt, ...)
|
|
|
|
{
|
2015-11-10 23:19:36 +00:00
|
|
|
static char STRINGIZE_STR[2048] = {0};
|
2015-08-17 05:26:58 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(STRINGIZE_STR, 2048, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
return STRINGIZE_STR;
|
|
|
|
}
|
2015-08-17 22:05:00 +00:00
|
|
|
|
2016-10-09 21:41:23 +00:00
|
|
|
const u64 CBasics::SECONDS_TO_2000 = 946684800LL;
|
|
|
|
const u64 CBasics::TICKS_PER_SECOND = 60750000LL;
|
|
|
|
|
|
|
|
OSTime CBasics::ToWiiTime(std::chrono::system_clock::time_point time)
|
|
|
|
{
|
|
|
|
time_t sysTime, tzDiff;
|
|
|
|
struct tm* gmTime;
|
|
|
|
|
|
|
|
sysTime = std::chrono::system_clock::to_time_t(time);
|
|
|
|
// Account for DST where needed
|
|
|
|
gmTime = localtime(&sysTime);
|
|
|
|
if (!gmTime)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Lazy way to get local time in sec
|
|
|
|
gmTime = gmtime(&sysTime);
|
|
|
|
tzDiff = sysTime - mktime(gmTime);
|
|
|
|
|
|
|
|
return OSTime(TICKS_PER_SECOND * ((sysTime + tzDiff) - SECONDS_TO_2000));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::chrono::system_clock::time_point CBasics::FromWiiTime(OSTime wiiTime)
|
|
|
|
{
|
|
|
|
time_t time = SECONDS_TO_2000 + wiiTime / TICKS_PER_SECOND;
|
|
|
|
|
|
|
|
time_t sysTime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
|
|
|
// Account for DST where needed
|
|
|
|
struct tm* gmTime = localtime(&sysTime);
|
|
|
|
if (!gmTime)
|
|
|
|
return std::chrono::system_clock::from_time_t(0);
|
|
|
|
|
|
|
|
// Lazy way to get local time in sec
|
|
|
|
gmTime = gmtime(&sysTime);
|
|
|
|
time_t tzDiff = sysTime - mktime(gmTime);
|
|
|
|
|
|
|
|
return std::chrono::system_clock::from_time_t(time - tzDiff);
|
|
|
|
}
|
|
|
|
|
2016-12-23 06:41:39 +00:00
|
|
|
OSCalendarTime CBasics::ToCalendarTime(OSTime time)
|
|
|
|
{
|
|
|
|
OSCalendarTime ret = {};
|
|
|
|
/* TODO: Finsh */
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-17 22:05:00 +00:00
|
|
|
}
|