AuroraRuntime/Include/Aurora/Time/Clock.hpp
Reece 7316aa0f8f [-/+] Nuke std::tm dependency from the public api
[*] Major bug in heap allocation, am brain damaged
2022-01-19 15:25:47 +00:00

156 lines
3.9 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Clock.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
namespace Aurora::Time
{
struct tm
{
int tm_sec {};
int tm_min {};
int tm_hour {};
int tm_mday {1};
int tm_mon {};
int tm_year {70};
int tm_wday {};
int tm_yday {};
int tm_isdst {-1};
template<typename Dest_t>
void CopyTo(Dest_t &out) const
{
out.tm_sec = tm_sec;
out.tm_min = tm_min;
out.tm_hour = tm_hour;
out.tm_mday = tm_mday;
out.tm_mon = tm_mon;
out.tm_year = tm_year;
out.tm_wday = tm_wday;
out.tm_yday = tm_yday;
out.tm_isdst = tm_isdst;
}
template<typename In_t>
void CopyFrom(const In_t &in)
{
tm_sec = in.tm_sec;
tm_min = in.tm_min;
tm_hour = in.tm_hour;
tm_mday = in.tm_mday;
tm_mon = in.tm_mon;
tm_year = in.tm_year;
tm_wday = in.tm_wday;
tm_yday = in.tm_yday;
tm_isdst = in.tm_isdst;
}
};
/**
Converts milliseconds from the Aurora epoch to a civil timestamp structure
similar to or of std::tm
Range: 1900 -> 2001 +- 2^63-1 ms
*/
AUKN_SYM tm ToCivilTime(AuInt64 time, bool UTC = true);
/**
Converts civil time to milliseconds from the Aurora epoch
Range: 1900 -> 2001 +- 2^63-1 ms
*/
AUKN_SYM AuInt64 FromCivilTime(const tm &time, bool UTC = true);
/**
Retrieves system clock in jiffies
*/
AUKN_SYM AuUInt64 CurrentClock();
/**
Retrieves system clock in milliseconds from the Aurora epoch
*/
AUKN_SYM AuUInt64 CurrentClockMS();
/**
Retrieves system clock in nanoseconds from the Aurora epoch
*/
AUKN_SYM AuUInt64 CurrentClockNS();
/**
Translates the Aurora epoch to the standard unix epoch
*/
AUKN_SYM AuInt64 ConvertAuroraToUnixMS(AuInt64 in);
/**
Translates the Aurora epoch to the standard unix epoch
*/
AUKN_SYM AuInt64 ConvertAuroraToUnixNS(AuInt64 in);
/**
Translates a standard unix epoch to the Aurora epoch
*/
AUKN_SYM AuInt64 ConvertUnixToAuroraMS(AuInt64 in);
/**
Translates a standard unix epoch to the Aurora epoch
*/
AUKN_SYM AuInt64 ConvertUnixToAuroraNS(AuInt64 in);
/**
Returns a high resolution count of jiffies with an undefined epoch from a
high resolution clock.
These values should not nor can be accurately converted meaningfully
*/
AUKN_SYM AuUInt64 CurrentInternalClock();
AUKN_SYM AuUInt64 CurrentInternalClockMS();
AUKN_SYM AuUInt64 CurrentInternalClockNS();
/**
Let's say you're fucked and you need a ball park figure.
Enjoy...
*/
AUKN_SYM AuUInt64 ConvertInternalToAuroraEpochMS(AuUInt64 in);
AUKN_SYM AuUInt64 ConvertInternalToAuroraEpochNS(AuUInt64 in);
/**
Converts seconds from the Aurora epoch to time_t
@deprecated
*/
AUKN_SYM time_t SToCTime(AuInt64 time);
/**
Converts nanoseconds from the Aurora epoch to time_t
@deprecated
*/
AUKN_SYM time_t NSToCTime(AuInt64 time);
/**
Converts milliseconds from the Aurora epoch to time_t
@deprecated
*/
AUKN_SYM time_t MSToCTime(AuInt64 time);
AUKN_SYM AuInt64 CTimeToMS(time_t time);
/**
Retrieves the freqency as a fraction of: jiffies per second / 1 * nanoseconds in a second
*/
AUKN_SYM double CPUFrequencyDeltaNS();
/**
Retrieves the freqency as a fraction of: jiffies per second / 1 * milliseconds in a second
*/
AUKN_SYM double CPUFrequencyDeltaMS();
/**
Retrieves the freqency of jiffies per second
*/
AUKN_SYM AuUInt64 ClockJiffies();
}