mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-18 16:17:14 +02:00
More additions to chrono utilities.
This commit is contained in:
@ -16,6 +16,26 @@ SQChar Datetime::Delimiter = ' ';
|
||||
SQChar Datetime::DateDelim = '-';
|
||||
SQChar Datetime::TimeDelim = ':';
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Datetime::Datetime(int64_t ts)
|
||||
: Datetime()
|
||||
{
|
||||
const auto y = static_cast< uint16_t >(std::lround(std::floor(ts / 3.17098e-14)));
|
||||
ts -= int64_t{y} * 3.17098e-14;
|
||||
const auto mo = static_cast< uint8_t >(std::lround(std::floor(ts / 2.628e+12)));
|
||||
ts -= int64_t{mo} * 2.628e+12;
|
||||
const auto d = static_cast< uint8_t >(std::lround(std::floor(ts / 8.64e+10)));
|
||||
ts -= int64_t{d} * 8.64e+10;
|
||||
const auto h = static_cast< uint8_t >(std::lround(std::floor(ts / 3.6e+9)));
|
||||
ts -= int64_t{h} * 3.6e+9;
|
||||
const auto mi = static_cast< uint8_t >(std::lround(std::floor(ts / 6e+7)));
|
||||
ts -= int64_t{mi} * 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 date-time
|
||||
Set(y, mo, d, h, mi, s, static_cast< uint16_t >(ts / 1000LL));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
int32_t Datetime::Compare(const Datetime & o) const
|
||||
{
|
||||
@ -745,6 +765,12 @@ Timestamp Datetime::GetTimestamp() const
|
||||
return Timestamp(ms);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
std::time_t Datetime::ToTimeT() const
|
||||
{
|
||||
return GetTimestamp().ToTimeT();
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_ChronoDatetime(HSQUIRRELVM vm, Table & /*cns*/)
|
||||
{
|
||||
|
Reference in New Issue
Block a user