diff --git a/Source/Utility/Timestamp.cpp b/Source/Utility/Timestamp.cpp index 88fd86a..bc4afc7 100644 --- a/Source/Utility/Timestamp.cpp +++ b/Source/Utility/Timestamp.cpp @@ -4,12 +4,73 @@ Timestamp::~Timestamp() { } +// FUNCTION: fn_18085 +TIMESTAMP_STRUCT Timestamp::ToSqlTimestamp() { + TIMESTAMP_STRUCT result{}; + if (this->seconds < 0) { + this->seconds = 0; + } + const std::tm* local = _localtime32(&this->seconds); + result.fraction = 0; + result.year = static_cast(local->tm_year + 1900); + result.month = static_cast(local->tm_mon + 1); + result.day = static_cast(local->tm_mday); + result.hour = static_cast(local->tm_hour); + result.minute = static_cast(local->tm_min); + result.second = static_cast(local->tm_sec); + return result; +} +// FUNCTION: fn_18086 +int Timestamp::IsBefore(__time32_t other) const { + return _difftime32(this->seconds, other) < 0.0; +} +// FUNCTION: fn_18087 +int Timestamp::IsBeforeNow() const { + __time32_t now; + _time32(&now); + return _difftime32(this->seconds, now) < 0.0; +} +// FUNCTION: fn_18088 +int Timestamp::Day() const { + return _localtime32(&this->seconds)->tm_mday; +} +// FUNCTION: fn_18089 +int Timestamp::Hour() const { + return _localtime32(&this->seconds)->tm_hour; +} +// FUNCTION: fn_18090 +int Timestamp::Minute() const { + return _localtime32(&this->seconds)->tm_min; +} +// FUNCTION: fn_18091 +int Timestamp::Month() const { + return _localtime32(&this->seconds)->tm_mon + 1; +} +// FUNCTION: fn_18092 +int Timestamp::Second() const { + return _localtime32(&this->seconds)->tm_sec; +} +// FUNCTION: fn_18093 +int Timestamp::Year() const { + return _localtime32(&this->seconds)->tm_year + 1900; +} + +// FUNCTION: fn_18094 +__time32_t Timestamp::SetDate(short year, short month, short day, short hour) { + std::tm local{}; + local.tm_hour = hour; + local.tm_mday = day; + local.tm_mon = month - 1; + local.tm_year = year - 1900; + this->seconds = _mktime32(&local); + return this->seconds; +}