mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-08 23:47:42 +00:00
MemoryCard PutTo implementations
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "CBasics.hpp"
|
||||
|
||||
@@ -20,4 +21,42 @@ const char* CBasics::Stringize(const char* fmt, ...)
|
||||
return STRINGIZE_STR;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user