More additions to chrono utilities.

This commit is contained in:
Sandu Liviu Catalin
2021-08-18 21:37:33 +03:00
parent 503b61c3df
commit 9d62233cfc
9 changed files with 410 additions and 4 deletions
+20
View File
@@ -12,6 +12,20 @@ SQMOD_DECL_TYPENAME(Typename, _SC("SqTime"))
// ------------------------------------------------------------------------------------------------
SQChar Time::Delimiter = ':';
// ------------------------------------------------------------------------------------------------
Time::Time(int64_t ts)
: Time()
{
const auto h = static_cast< uint8_t >(std::lround(std::floor(ts / 3.6e+9)));
ts -= int64_t{h} * 3.6e+9;
const auto m = static_cast< uint8_t >(std::lround(std::floor(ts / 6e+7)));
ts -= int64_t{m} * 6e+7;
const auto s = static_cast< uint8_t >(std::lround(std::floor(ts / 1e+6)));
ts -= int64_t{s} * 1e+6;
// Set the specified time
Set(h, m, s, static_cast< uint16_t >(ts / 1000LL));
}
// ------------------------------------------------------------------------------------------------
int32_t Time::Compare(const Time & o) const
{
@@ -410,6 +424,12 @@ Timestamp Time::GetTimestamp() const
return Timestamp(ms);
}
// ------------------------------------------------------------------------------------------------
std::time_t Time::ToTimeT() const
{
return GetTimestamp().ToTimeT();
}
// ================================================================================================
void Register_ChronoTime(HSQUIRRELVM vm, Table & /*cns*/)
{