[*] All CivilTime APIs should just use ETimezoneShift

This commit is contained in:
Reece Wilson 2023-09-22 06:18:55 +01:00
parent f6437ef66e
commit dfecf10f1d
5 changed files with 21 additions and 22 deletions

View File

@ -19,18 +19,20 @@ namespace Aurora::Time
Converts milliseconds from the Aurora epoch to a civil timestamp structure
similar to or of std::tm
*/
AUKN_SYM tm ToCivilTime(AuInt64 time, bool bIsUTC = true);
AUKN_SYM tm ToCivilTime(AuInt64 time, ETimezoneShift civilTimezoneShift = ETimezoneShift::eUTC);
/**
Converts civil time to milliseconds from the Aurora epoch
*/
AUKN_SYM AuInt64 FromCivilTime(const tm &time, bool bIsUTC = true);
AUKN_SYM AuInt64 FromCivilTime(const tm &time, ETimezoneShift civilTimezoneUnshift = ETimezoneShift::eUTC);
/**
Normalizes a civil data structure with respect to UTC, given the two input parameters 'in' civil and 'shiftFrom' timezone hint
*/
AUKN_SYM tm NormalizeCivilTimezone(const tm &in, ETimezoneShift shiftFrom = ETimezoneShift::eUTC);
AUKN_SYM tm NormalizeCivilTimezone(const tm &in,
ETimezoneShift civilTimezoneUnshift = ETimezoneShift::eUTC);
/**
Translates the Aurora epoch to the standard unix epoch
@ -53,7 +55,6 @@ namespace Aurora::Time
AUKN_SYM AuInt64 ConvertUnixToAuroraNS(AuInt64 in);
/**
Converts seconds from the Aurora epoch to time_t
*/
@ -70,12 +71,4 @@ namespace Aurora::Time
AUKN_SYM time_t MSToCTime(AuInt64 time);
AUKN_SYM AuInt64 CTimeToMS(time_t time);
// TODO: Unix style of GetClockTimeNSByEnum/GetClockResNSByEnum?
//
// Interfaces make sense for code that would like to deal with abstract clocks
// Accessing a single by a single query-clock API makes sense for general purpose use (eg: GetWallTimeNS/CurrentClockNS, SteadyClockNS(), ...)
//
// A potential GetClock[Time/Res][NS]ByEnum(EClock::...) feels too bloated, but it is a nice hybrid between the two use cases
}

View File

@ -19,7 +19,9 @@ namespace Aurora::Console
{
std::tm localized;
Aurora::Time::ToCivilTime(msg.time, utc).CopyTo(localized);
Time::ToCivilTime(msg.time, utc ?
Time::ETimezoneShift::eUTC :
Time::ETimezoneShift::eLocalTime).CopyTo(localized);
if (simple)
{

View File

@ -171,12 +171,12 @@ namespace Aurora::Crypto::X509
}
{
auto issueNorm = AuTime::ToCivilTime(request.iIssuedDateMs, true);
auto issueNorm = AuTime::ToCivilTime(request.iIssuedDateMs, AuTime::ETimezoneShift::eUTC);
auto issue = fmt::format("{:04}{:02}{:02}{:02}{:02}{:02}",
issueNorm.tm_year + 1900, issueNorm.tm_mon + 1, issueNorm.tm_mday,
issueNorm.tm_hour, issueNorm.tm_min, issueNorm.tm_sec);
auto expireNorm = AuTime::ToCivilTime(request.iExpirationDateMs, true);
auto expireNorm = AuTime::ToCivilTime(request.iExpirationDateMs, AuTime::ETimezoneShift::eUTC);
auto expire = fmt::format("{:04}{:02}{:02}{:02}{:02}{:02}",
expireNorm.tm_year + 1900, expireNorm.tm_mon + 1, expireNorm.tm_mday,
expireNorm.tm_hour, expireNorm.tm_min, expireNorm.tm_sec);

View File

@ -351,7 +351,7 @@ namespace Aurora::Crypto::X509
tm.tm_sec = time.sec;
tm.tm_min = time.min;
tm.tm_hour = time.hour;
return AuTime::FromCivilTime(tm, true);
return AuTime::FromCivilTime(tm, AuTime::ETimezoneShift::eUTC);
}
static void FindUsage(DecodedCertificate &out,

View File

@ -102,11 +102,11 @@ namespace Aurora::Time
return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::nanoseconds(in) - gUnixDelta).count();
}
AUKN_SYM tm ToCivilTime(AuInt64 time, bool UTC)
AUKN_SYM tm ToCivilTime(AuInt64 time, ETimezoneShift shift)
{
std::tm ret {};
auto timet = MSToCTime(time);
if (UTC)
if (shift == ETimezoneShift::eUTC)
{
#if defined(AURORA_COMPILER_MSVC)
auto tm = gmtime_s(&ret, &timet);
@ -129,7 +129,11 @@ namespace Aurora::Time
#endif
{
SysPushErrorGeneric("Couldn't convert local civil time");
return ToCivilTime(time, true);
#if 0
SysPanic();
#else
return ToCivilTime(time, ETimezoneShift::eUTC);
#endif
}
}
tm _;
@ -137,14 +141,14 @@ namespace Aurora::Time
return _;
}
AUKN_SYM AuInt64 FromCivilTime(const tm &time, bool UTC)
AUKN_SYM AuInt64 FromCivilTime(const tm &time, ETimezoneShift shift)
{
::tm tm;
time_t timet;
time.CopyTo(tm);
if (UTC)
if (shift == ETimezoneShift::eUTC)
{
tm.tm_isdst = 0;
timet = timegm(&tm);
@ -170,6 +174,6 @@ namespace Aurora::Time
return time;
}
return ToCivilTime(FromCivilTime(time, shift == ETimezoneShift::eUTC));
return ToCivilTime(FromCivilTime(time, shift));
}
}