1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-15 22:57:12 +02:00

Major plugin refactor and cleanup.

Switched to POCO library for unified platform/library interface.
Deprecated the external module API. It was creating more problems than solving.
Removed most built-in libraries in favor of system libraries for easier maintenance.
Cleaned and secured code with help from static analyzers.
This commit is contained in:
Sandu Liviu Catalin
2021-01-30 08:51:39 +02:00
parent e0e34b4030
commit 4a6bfc086c
6219 changed files with 1209835 additions and 454916 deletions

View File

@ -1,28 +1,26 @@
// ------------------------------------------------------------------------------------------------
#include "Library/Chrono/Date.hpp"
#include "Library/Chrono/Time.hpp"
#include "Library/Chrono/Datetime.hpp"
#include "Library/Chrono/Timestamp.hpp"
#include "Base/Shared.hpp"
#include "Core/Utility.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqDate"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqDate"))
// ------------------------------------------------------------------------------------------------
SQChar Date::Delimiter = '-';
// ------------------------------------------------------------------------------------------------
Int32 Date::Compare(const Date & o) const
int32_t Date::Compare(const Date & o) const
{
if (m_Year < o.m_Year)
{
{ // NOLINT(bugprone-branch-clone)
return -1;
}
else if (m_Year > o.m_Year)
{
{ // NOLINT(bugprone-branch-clone)
return 1;
}
else if (m_Month < o.m_Month)
@ -71,13 +69,13 @@ Date Date::operator / (const Date & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr Date::ToString() const
String Date::ToString() const
{
return ToStrF("%04u%c%02u%c%02u", m_Year, m_Delimiter, m_Month, m_Delimiter, m_Day);
return fmt::format("{:04}{}{:02}{}{:02}", m_Year, m_Delimiter, m_Month, m_Delimiter, m_Day);
}
// ------------------------------------------------------------------------------------------------
void Date::Set(Uint16 year, Uint8 month, Uint8 day)
void Date::Set(uint16_t year, uint8_t month, uint8_t day)
{
if (!Chrono::ValidDate(year, month, day))
{
@ -90,7 +88,7 @@ void Date::Set(Uint16 year, Uint8 month, Uint8 day)
}
// ------------------------------------------------------------------------------------------------
void Date::SetStr(CSStr str)
void Date::SetStr(const SQChar * str)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %u - %u - %u ");
@ -108,21 +106,21 @@ void Date::SetStr(CSStr str)
fs[4] = m_Delimiter;
fs[9] = m_Delimiter;
// The sscanf function requires at least 32 bit integers
Uint32 year = 0, month = 0, day = 0;
uint32_t year = 0, month = 0, day = 0;
// Attempt to extract the component values from the specified string
sscanf(str, fs, &year, &month, &day);
// Clamp the extracted values to the boundaries of associated type and assign them
Set(ClampL< Uint32, Uint8 >(year),
ClampL< Uint32, Uint8 >(month),
ClampL< Uint32, Uint8 >(day)
Set(ClampL< uint32_t, uint8_t >(year),
ClampL< uint32_t, uint8_t >(month),
ClampL< uint32_t, uint8_t >(day)
);
}
// ------------------------------------------------------------------------------------------------
void Date::SetDayOfYear(Uint16 doy)
void Date::SetDayOfYear(uint16_t doy)
{
// Reverse the given day of year to a full date
Date d = Chrono::ReverseDayOfyear(m_Year, doy);
Date d = Chrono::ReverseDayOfYear(m_Year, doy);
// Set the obtained month
SetMonth(d.m_Month);
// Set the obtained day
@ -130,7 +128,7 @@ void Date::SetDayOfYear(Uint16 doy)
}
// ------------------------------------------------------------------------------------------------
void Date::SetYear(Uint16 year)
void Date::SetYear(uint16_t year)
{
// Make sure the year is valid
if (!year)
@ -148,7 +146,7 @@ void Date::SetYear(Uint16 year)
}
// ------------------------------------------------------------------------------------------------
void Date::SetMonth(Uint8 month)
void Date::SetMonth(uint8_t month)
{
// Make sure the month is valid
if (month == 0 || month > 12)
@ -165,10 +163,10 @@ void Date::SetMonth(Uint8 month)
}
// ------------------------------------------------------------------------------------------------
void Date::SetDay(Uint8 day)
void Date::SetDay(uint8_t day)
{
// Grab the amount of days in the current month
const Uint8 dim = Chrono::DaysInMonth(m_Year, m_Month);
const uint8_t dim = Chrono::DaysInMonth(m_Year, m_Month);
// Make sure the day is valid
if (day == 0)
{
@ -183,26 +181,26 @@ void Date::SetDay(Uint8 day)
}
// ------------------------------------------------------------------------------------------------
Date & Date::AddYears(Int32 years)
Date & Date::AddYears(int32_t years)
{
// Do we have a valid amount of years?
if (years)
{
// Add the specified amount of years
SetYear(ConvTo< Uint16 >::From(static_cast< Int32 >(m_Year) + years));
SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
}
// Allow chaining operations
return *this;
}
// ------------------------------------------------------------------------------------------------
Date & Date::AddMonths(Int32 months)
Date & Date::AddMonths(int32_t months)
{
// Do we have a valid amount of months?
if (months)
{
// Extract the number of years
Int32 years = static_cast< Int32 >(months / 12);
auto years = static_cast< int32_t >(months / 12);
// Extract the number of months
months = (months % 12) + m_Month;
// Do we have extra months?
@ -223,47 +221,47 @@ Date & Date::AddMonths(Int32 months)
// Are there any years to add?
if (years)
{
SetYear(ConvTo< Uint16 >::From(static_cast< Int32 >(m_Year) + years));
SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
}
// Add the months
SetMonth(months);
SetMonth(static_cast< uint8_t >(months));
}
// Allow chaining operations
return *this;
}
// ------------------------------------------------------------------------------------------------
Date & Date::AddDays(Int32 days)
Date & Date::AddDays(int32_t days)
{
// Do we have a valid amount of days?
if (days)
{
// Whether the number of days is positive or negative
const Int32 dir = days > 0 ? 1 : -1;
const int32_t dir = days > 0 ? 1 : -1;
// Grab current year
Int32 year = m_Year;
int32_t year = m_Year;
// Calculate the days in the current year
Int32 diy = Chrono::DaysInYear(year);
int32_t diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
// Calculate the day of year
Int32 doy = GetDayOfYear() + days;
int32_t doy = GetDayOfYear() + days;
// Calculate the resulting years
while (doy > diy || doy < 0)
{
doy -= diy * dir;
year += dir;
diy = Chrono::DaysInYear(year);
diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
}
// Set the obtained year
SetYear(year);
SetYear(static_cast< uint16_t >(year));
// Set the obtained day of year
SetDayOfYear(doy);
SetDayOfYear(static_cast< uint16_t >(doy));
}
// Allow chaining operations
return *this;
}
// ------------------------------------------------------------------------------------------------
Date Date::AndYears(Int32 years)
Date Date::AndYears(int32_t years)
{
// Do we have a valid amount of years?
if (!years)
@ -273,13 +271,13 @@ Date Date::AndYears(Int32 years)
// Replicate the current date
Date d(*this);
// Add the specified amount of years
d.SetYear(ConvTo< Uint16 >::From(static_cast< Int32 >(m_Year) + years));
d.SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
// Return the resulted date
return d;
}
// ------------------------------------------------------------------------------------------------
Date Date::AndMonths(Int32 months)
Date Date::AndMonths(int32_t months)
{
// Do we have a valid amount of months?
if (!months)
@ -287,7 +285,7 @@ Date Date::AndMonths(Int32 months)
return Date(*this); // Return the date as is
}
// Extract the number of years
Int32 years = static_cast< Int32 >(months / 12);
auto years = static_cast< int32_t >(months / 12);
// Extract the number of months
months = (months % 12) + m_Month;
// Do we have extra months?
@ -310,16 +308,16 @@ Date Date::AndMonths(Int32 months)
// Are there any years to add?
if (years)
{
d.SetYear(ConvTo< Uint16 >::From(static_cast< Int32 >(m_Year) + years));
d.SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
}
// Add the months
d.SetMonth(months);
d.SetMonth(static_cast< uint8_t >(months));
// Return the resulted date
return d;
}
// ------------------------------------------------------------------------------------------------
Date Date::AndDays(Int32 days)
Date Date::AndDays(int32_t days)
{
// Do we have a valid amount of days?
if (!days)
@ -327,26 +325,26 @@ Date Date::AndDays(Int32 days)
return Date(*this); // Return the date as is
}
// Whether the number of days is positive or negative
const Int32 dir = days > 0 ? 1 : -1;
const int32_t dir = days > 0 ? 1 : -1;
// Grab current year
Int32 year = m_Year;
int32_t year = m_Year;
// Calculate the days in the current year
Int32 diy = Chrono::DaysInYear(year);
int32_t diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
// Calculate the day of year
Int32 doy = GetDayOfYear() + days;
int32_t doy = GetDayOfYear() + days;
// Calculate the resulting years
while (doy > diy || doy < 0)
{
doy -= diy * dir;
year += dir;
diy = Chrono::DaysInYear(year);
diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
}
// Replicate the current date
Date d(*this);
// Set the obtained year
d.SetYear(year);
d.SetYear(static_cast< uint16_t >(year));
// Set the obtained day of year
d.SetDayOfYear(doy);
d.SetDayOfYear(static_cast< uint16_t >(doy));
// Return the resulted date
return d;
}
@ -355,14 +353,14 @@ Date Date::AndDays(Int32 days)
Timestamp Date::GetTimestamp() const
{
// Calculate the current day of the year
Int32 days = Chrono::DayOfYear(m_Year, m_Month, m_Day);
int32_t days = Chrono::DayOfYear(m_Year, m_Month, m_Day);
// Calculate all days till the current year
for (Int32 year = 0; year < m_Year; --year)
for (int32_t year = 0; year < m_Year; --year)
{
days += Chrono::DaysInYear(year);
days += Chrono::DaysInYear(static_cast< uint16_t >(year));
}
// Return the resulted timestamp
return Timestamp(static_cast< Int64 >(days * 86400000000LL));
return Timestamp(static_cast< int64_t >(days * 86400000000LL));
}
// ================================================================================================
@ -372,9 +370,9 @@ void Register_ChronoDate(HSQUIRRELVM vm, Table & /*cns*/)
Class< Date >(vm, Typename::Str)
// Constructors
.Ctor()
.Ctor< Uint16 >()
.Ctor< Uint16, Uint8 >()
.Ctor< Uint16, Uint8, Uint8 >()
.Ctor< uint16_t >()
.Ctor< uint16_t, uint8_t >()
.Ctor< uint16_t, uint8_t, uint8_t >()
// Static Properties
.SetStaticValue(_SC("GlobalDelimiter"), &Date::Delimiter)
// Core Meta-methods
@ -405,9 +403,9 @@ void Register_ChronoDate(HSQUIRRELVM vm, Table & /*cns*/)
.Func(_SC("AndMonths"), &Date::AndMonths)
.Func(_SC("AndDays"), &Date::AndDays)
// Overloaded Methods
.Overload< void (Date::*)(Uint16) >(_SC("Set"), &Date::Set)
.Overload< void (Date::*)(Uint16, Uint8) >(_SC("Set"), &Date::Set)
.Overload< void (Date::*)(Uint16, Uint8, Uint8) >(_SC("Set"), &Date::Set)
.Overload< void (Date::*)(uint16_t) >(_SC("Set"), &Date::Set)
.Overload< void (Date::*)(uint16_t, uint8_t) >(_SC("Set"), &Date::Set)
.Overload< void (Date::*)(uint16_t, uint8_t, uint8_t) >(_SC("Set"), &Date::Set)
);
}

View File

@ -19,9 +19,9 @@ public:
private:
// ------------------------------------------------------------------------------------------------
Uint16 m_Year; // Year
Uint8 m_Month; // Month
Uint8 m_Day; // Day
uint16_t m_Year{}; // Year
uint8_t m_Month{}; // Month
uint8_t m_Day{}; // Day
// ------------------------------------------------------------------------------------------------
SQChar m_Delimiter; // Component delimiter when generating strings.
@ -31,7 +31,7 @@ protected:
/* ------------------------------------------------------------------------------------------------
* Compare the values of two instances.
*/
Int32 Compare(const Date & o) const;
SQMOD_NODISCARD int32_t Compare(const Date & o) const;
public:
@ -48,27 +48,27 @@ public:
}
/* ------------------------------------------------------------------------------------------------
* Speciffic year constructor.
* Specific year constructor.
*/
Date(Uint16 year)
explicit Date(uint16_t year)
: m_Delimiter(Delimiter)
{
Set(year, 1, 1);
}
/* ------------------------------------------------------------------------------------------------
* Speciffic year and month constructor.
* Specific year and month constructor.
*/
Date(Uint16 year, Uint8 month)
Date(uint16_t year, uint8_t month)
: m_Delimiter(Delimiter)
{
Set(year, month, 1);
}
/* ------------------------------------------------------------------------------------------------
* Speciffic date constructor.
* Specific date constructor.
*/
Date(Uint16 year, Uint8 month, Uint8 day)
Date(uint16_t year, uint8_t month, uint8_t day)
: m_Delimiter(Delimiter)
{
Set(year, month, day);
@ -77,7 +77,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* String constructor.
*/
Date(CSStr str)
explicit Date(const SQChar * str)
: m_Delimiter(Delimiter)
{
SetStr(str);
@ -179,7 +179,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Date & o) const
SQMOD_NODISCARD int32_t Cmp(const Date & o) const
{
return Compare(o);
}
@ -187,12 +187,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year)
void Set(uint16_t year)
{
Set(year, m_Month, m_Day);
}
@ -200,7 +200,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year, Uint8 month)
void Set(uint16_t year, uint8_t month)
{
Set(year, month, m_Day);
}
@ -208,12 +208,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year, Uint8 month, Uint8 day);
void Set(uint16_t year, uint8_t month, uint8_t day);
/* ------------------------------------------------------------------------------------------------
* Retrieve the local delimiter character.
*/
SQChar GetDelimiter() const
SQMOD_NODISCARD SQChar GetDelimiter() const
{
return m_Delimiter;
}
@ -229,7 +229,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the values as a string.
*/
CSStr GetStr() const
SQMOD_NODISCARD String GetStr() const
{
return ToString();
}
@ -237,12 +237,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Extract the values from a string.
*/
void SetStr(CSStr str);
void SetStr(const SQChar * str);
/* ------------------------------------------------------------------------------------------------
* Retrieve the day component.
*/
Uint16 GetDayOfYear() const
SQMOD_NODISCARD uint16_t GetDayOfYear() const
{
return Chrono::DayOfYear(m_Year, m_Month, m_Day);
}
@ -250,12 +250,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the day component.
*/
void SetDayOfYear(Uint16 doy);
void SetDayOfYear(uint16_t doy);
/* ------------------------------------------------------------------------------------------------
* Retrieve the year component.
*/
Uint16 GetYear() const
SQMOD_NODISCARD uint16_t GetYear() const
{
return m_Year;
}
@ -263,12 +263,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the year component.
*/
void SetYear(Uint16 year);
void SetYear(uint16_t year);
/* ------------------------------------------------------------------------------------------------
* Retrieve the month component.
*/
Uint8 GetMonth() const
SQMOD_NODISCARD uint8_t GetMonth() const
{
return m_Month;
}
@ -276,12 +276,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the month component.
*/
void SetMonth(Uint8 month);
void SetMonth(uint8_t month);
/* ------------------------------------------------------------------------------------------------
* Retrieve the day component.
*/
Uint8 GetDay() const
SQMOD_NODISCARD uint8_t GetDay() const
{
return m_Day;
}
@ -289,42 +289,42 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the day component.
*/
void SetDay(Uint8 day);
void SetDay(uint8_t day);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of years to the current date.
*/
Date & AddYears(Int32 years);
Date & AddYears(int32_t years);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of months to the current date.
*/
Date & AddMonths(Int32 months);
Date & AddMonths(int32_t months);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of days to the current date.
*/
Date & AddDays(Int32 days);
Date & AddDays(int32_t days);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of years to obtain a new date.
*/
Date AndYears(Int32 years);
SQMOD_NODISCARD Date AndYears(int32_t years);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of months to obtain a new date.
*/
Date AndMonths(Int32 months);
SQMOD_NODISCARD Date AndMonths(int32_t months);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of days to obtain a new date.
*/
Date AndDays(Int32 days);
SQMOD_NODISCARD Date AndDays(int32_t days);
/* ------------------------------------------------------------------------------------------------
* See whether the associated year is a leap year.
*/
bool IsThisLeapYear() const
SQMOD_NODISCARD bool IsThisLeapYear() const
{
return Chrono::IsLeapYear(m_Year);
}
@ -332,7 +332,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the number of days in the associated year.
*/
Uint16 GetYearDays() const
SQMOD_NODISCARD uint16_t GetYearDays() const
{
return Chrono::DaysInYear(m_Year);
}
@ -340,7 +340,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the number of days in the associated month.
*/
Uint8 GetMonthDays() const
SQMOD_NODISCARD uint8_t GetMonthDays() const
{
return Chrono::DaysInMonth(m_Year, m_Month);
}
@ -348,7 +348,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Convert this date instance to a time-stamp.
*/
Timestamp GetTimestamp() const;
SQMOD_NODISCARD Timestamp GetTimestamp() const;
};
} // Namespace:: SqMod

View File

@ -3,13 +3,13 @@
#include "Library/Chrono/Date.hpp"
#include "Library/Chrono/Time.hpp"
#include "Library/Chrono/Timestamp.hpp"
#include "Base/Shared.hpp"
#include "Core/Utility.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqDatetime"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqDatetime"))
// ------------------------------------------------------------------------------------------------
SQChar Datetime::Delimiter = ' ';
@ -17,14 +17,14 @@ SQChar Datetime::DateDelim = '-';
SQChar Datetime::TimeDelim = ':';
// ------------------------------------------------------------------------------------------------
Int32 Datetime::Compare(const Datetime & o) const
int32_t Datetime::Compare(const Datetime & o) const
{
if (m_Year < o.m_Year)
{
{ // NOLINT(bugprone-branch-clone)
return -1;
}
else if (m_Year > o.m_Year)
{
{ // NOLINT(bugprone-branch-clone)
return 1;
}
else if (m_Month < o.m_Month)
@ -107,9 +107,9 @@ Datetime Datetime::operator / (const Datetime & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr Datetime::ToString() const
String Datetime::ToString() const
{
return ToStrF("%04u%c%02u%c%02u%c%02u%c%02u%c%02u%c%u"
return fmt::format("{:04}{}{:02}{}{:02}{}{:02}{}{:02}{}{:02}{}{}"
, m_Year, m_DateDelim, m_Month, m_DateDelim, m_Day
, m_Delimiter
, m_Hour, m_TimeDelim, m_Minute, m_TimeDelim, m_Second , m_TimeDelim, m_Millisecond
@ -117,7 +117,7 @@ CSStr Datetime::ToString() const
}
// ------------------------------------------------------------------------------------------------
void Datetime::Set(Uint16 year, Uint8 month, Uint8 day, Uint8 hour, Uint8 minute, Uint8 second, Uint16 millisecond)
void Datetime::Set(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint16_t millisecond)
{
// Validate the specified date
if (!Chrono::ValidDate(year, month, day))
@ -159,7 +159,7 @@ void Datetime::Set(Uint16 year, Uint8 month, Uint8 day, Uint8 hour, Uint8 minute
}
// ------------------------------------------------------------------------------------------------
void Datetime::SetStr(CSStr str)
void Datetime::SetStr(const SQChar * str)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %u - %u - %u %u : %u : %u : %u ");
@ -185,25 +185,25 @@ void Datetime::SetStr(CSStr str)
fs[24] = m_TimeDelim;
fs[29] = m_TimeDelim;
// The sscanf function requires at least 32 bit integers
Uint32 year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, milli = 0;
uint32_t year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, milli = 0;
// Attempt to extract the component values from the specified string
sscanf(str, fs, &year, &month, &day, &hour, &minute, &second, &milli);
// Clamp the extracted values to the boundaries of associated type and assign them
Set(ClampL< Uint32, Uint8 >(year),
ClampL< Uint32, Uint8 >(month),
ClampL< Uint32, Uint8 >(day),
ClampL< Uint32, Uint8 >(hour),
ClampL< Uint32, Uint8 >(minute),
ClampL< Uint32, Uint8 >(second),
ClampL< Uint32, Uint16 >(milli)
Set(ClampL< uint32_t, uint8_t >(year),
ClampL< uint32_t, uint8_t >(month),
ClampL< uint32_t, uint8_t >(day),
ClampL< uint32_t, uint8_t >(hour),
ClampL< uint32_t, uint8_t >(minute),
ClampL< uint32_t, uint8_t >(second),
ClampL< uint32_t, uint16_t >(milli)
);
}
// ------------------------------------------------------------------------------------------------
void Datetime::SetDayOfYear(Uint16 doy)
void Datetime::SetDayOfYear(uint16_t doy)
{
// Reverse the given day of year to a full date
Date d = Chrono::ReverseDayOfyear(m_Year, doy);
Date d = Chrono::ReverseDayOfYear(m_Year, doy);
// Set the obtained month
SetMonth(d.GetMonth());
// Set the obtained day
@ -211,7 +211,7 @@ void Datetime::SetDayOfYear(Uint16 doy)
}
// ------------------------------------------------------------------------------------------------
void Datetime::SetYear(Uint16 year)
void Datetime::SetYear(uint16_t year)
{
// Make sure the year is valid
if (!year)
@ -229,7 +229,7 @@ void Datetime::SetYear(Uint16 year)
}
// ------------------------------------------------------------------------------------------------
void Datetime::SetMonth(Uint8 month)
void Datetime::SetMonth(uint8_t month)
{
// Make sure the month is valid
if (month == 0 || month > 12)
@ -246,10 +246,10 @@ void Datetime::SetMonth(Uint8 month)
}
// ------------------------------------------------------------------------------------------------
void Datetime::SetDay(Uint8 day)
void Datetime::SetDay(uint8_t day)
{
// Grab the amount of days in the current month
const Uint8 dim = Chrono::DaysInMonth(m_Year, m_Month);
const uint8_t dim = Chrono::DaysInMonth(m_Year, m_Month);
// Make sure the day is valid
if (day == 0)
{
@ -264,7 +264,7 @@ void Datetime::SetDay(Uint8 day)
}
// ------------------------------------------------------------------------------------------------
void Datetime::SetHour(Uint8 hour)
void Datetime::SetHour(uint8_t hour)
{
// Is the specified hour within range?
if (hour >= 24)
@ -276,7 +276,7 @@ void Datetime::SetHour(Uint8 hour)
}
// ------------------------------------------------------------------------------------------------
void Datetime::SetMinute(Uint8 minute)
void Datetime::SetMinute(uint8_t minute)
{
// Is the specified minute within range?
if (minute >= 60)
@ -288,7 +288,7 @@ void Datetime::SetMinute(Uint8 minute)
}
// ------------------------------------------------------------------------------------------------
void Datetime::SetSecond(Uint8 second)
void Datetime::SetSecond(uint8_t second)
{
// Is the specified second within range?
if (second >= 60)
@ -300,7 +300,7 @@ void Datetime::SetSecond(Uint8 second)
}
// ------------------------------------------------------------------------------------------------
void Datetime::SetMillisecond(Uint16 millisecond)
void Datetime::SetMillisecond(uint16_t millisecond)
{
// Is the specified millisecond within range?
if (millisecond >= 1000)
@ -312,26 +312,26 @@ void Datetime::SetMillisecond(Uint16 millisecond)
}
// ------------------------------------------------------------------------------------------------
Datetime & Datetime::AddYears(Int32 years)
Datetime & Datetime::AddYears(int32_t years)
{
// Do we have a valid amount of years?
if (years)
{
// Add the specified amount of years
SetYear(ConvTo< Uint16 >::From(static_cast< Int32 >(m_Year) + years));
SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
}
// Allow chaining operations
return *this;
}
// ------------------------------------------------------------------------------------------------
Datetime & Datetime::AddMonths(Int32 months)
Datetime & Datetime::AddMonths(int32_t months)
{
// Do we have a valid amount of months?
if (months)
{
// Extract the number of years
Int32 years = static_cast< Int32 >(months / 12);
auto years = static_cast< int32_t >(months / 12);
// Extract the number of months
months = (months % 12) + m_Month;
// Do we have extra months?
@ -352,53 +352,53 @@ Datetime & Datetime::AddMonths(Int32 months)
// Are there any years to add?
if (years)
{
SetYear(ConvTo< Uint16 >::From(static_cast< Int32 >(m_Year) + years));
SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
}
// Add the months
SetMonth(months);
SetMonth(static_cast< uint8_t >(months));
}
// Allow chaining operations
return *this;
}
// ------------------------------------------------------------------------------------------------
Datetime & Datetime::AddDays(Int32 days)
Datetime & Datetime::AddDays(int32_t days)
{
// Do we have a valid amount of days?
if (days)
{
// Whether the number of days is positive or negative
const Int32 dir = days > 0 ? 1 : -1;
const int32_t dir = days > 0 ? 1 : -1;
// Grab current year
Int32 year = m_Year;
int32_t year = m_Year;
// Calculate the days in the current year
Int32 diy = Chrono::DaysInYear(year);
int32_t diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
// Calculate the day of year
Int32 doy = GetDayOfYear() + days;
int32_t doy = GetDayOfYear() + days;
// Calculate the resulting years
while (doy > diy || doy < 0)
{
doy -= diy * dir;
year += dir;
diy = Chrono::DaysInYear(year);
diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
}
// Set the obtained year
SetYear(year);
SetYear(static_cast< uint16_t >(year));
// Set the obtained day of year
SetDayOfYear(doy);
SetDayOfYear(static_cast< uint16_t >(doy));
}
// Allow chaining operations
return *this;
}
// ------------------------------------------------------------------------------------------------
Datetime & Datetime::AddHours(Int32 hours)
Datetime & Datetime::AddHours(int32_t hours)
{
// Did we even add any hours?
if (hours)
{
// Extract the number of days
Int32 days = static_cast< Int32 >(hours / 24);
auto days = static_cast< int32_t >(hours / 24);
// Extract the number of hours
m_Hour += (hours % 24);
// Are the hours overlapping with the next day?
@ -420,13 +420,13 @@ Datetime & Datetime::AddHours(Int32 hours)
}
// ------------------------------------------------------------------------------------------------
Datetime & Datetime::AddMinutes(Int32 minutes)
Datetime & Datetime::AddMinutes(int32_t minutes)
{
// Did we even add any minutes?
if (minutes)
{
// Extract the number of hours
Int32 hours = static_cast< Int32 >(minutes / 60);
auto hours = static_cast< int32_t >(minutes / 60);
// Extract the number of minutes
m_Minute += (minutes % 60);
// Are the minutes overlapping with the next hour?
@ -448,13 +448,13 @@ Datetime & Datetime::AddMinutes(Int32 minutes)
}
// ------------------------------------------------------------------------------------------------
Datetime & Datetime::AddSeconds(Int32 seconds)
Datetime & Datetime::AddSeconds(int32_t seconds)
{
// Did we even add any seconds?
if (seconds)
{
// Extract the number of minutes
Int32 minutes = static_cast< Int32 >(seconds / 60);
auto minutes = static_cast< int32_t >(seconds / 60);
// Extract the number of seconds
m_Second += (seconds % 60);
// Are the seconds overlapping with the next minute?
@ -476,13 +476,13 @@ Datetime & Datetime::AddSeconds(Int32 seconds)
}
// ------------------------------------------------------------------------------------------------
Datetime & Datetime::AddMilliseconds(Int32 milliseconds)
Datetime & Datetime::AddMilliseconds(int32_t milliseconds)
{
// Did we even add any milliseconds?
if (milliseconds)
{
// Extract the number of seconds
Int32 seconds = static_cast< Int32 >(milliseconds / 1000);
auto seconds = static_cast< int32_t >(milliseconds / 1000);
// Extract the number of milliseconds
m_Millisecond += (milliseconds / 1000);
// Are the milliseconds overlapping with the next second?
@ -504,7 +504,7 @@ Datetime & Datetime::AddMilliseconds(Int32 milliseconds)
}
// ------------------------------------------------------------------------------------------------
Datetime Datetime::AndYears(Int32 years)
Datetime Datetime::AndYears(int32_t years)
{
// Do we have a valid amount of years?
if (!years)
@ -514,13 +514,13 @@ Datetime Datetime::AndYears(Int32 years)
// Replicate the current date
Datetime dt(*this);
// Add the specified amount of years
dt.SetYear(ConvTo< Uint16 >::From(static_cast< Int32 >(m_Year) + years));
dt.SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
// Return the resulted date
return dt;
}
// ------------------------------------------------------------------------------------------------
Datetime Datetime::AndMonths(Int32 months)
Datetime Datetime::AndMonths(int32_t months)
{
// Do we have a valid amount of months?
if (!months)
@ -528,7 +528,7 @@ Datetime Datetime::AndMonths(Int32 months)
return Datetime(*this); // Return the date-time as is
}
// Extract the number of years
Int32 years = static_cast< Int32 >(months / 12);
auto years = static_cast< int32_t >(months / 12);
// Extract the number of months
months = (months % 12) + m_Month;
// Do we have extra months?
@ -551,16 +551,16 @@ Datetime Datetime::AndMonths(Int32 months)
// Are there any years to add?
if (years)
{
dt.SetYear(ConvTo< Uint16 >::From(static_cast< Int32 >(m_Year) + years));
dt.SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
}
// Add the months
dt.SetMonth(months);
dt.SetMonth(static_cast< uint8_t >(months));
// Return the resulted date
return dt;
}
// ------------------------------------------------------------------------------------------------
Datetime Datetime::AndDays(Int32 days)
Datetime Datetime::AndDays(int32_t days)
{
// Do we have a valid amount of days?
if (!days)
@ -568,32 +568,32 @@ Datetime Datetime::AndDays(Int32 days)
return Datetime(*this); // Return the date-time as is
}
// Whether the number of days is positive or negative
const Int32 dir = days > 0 ? 1 : -1;
const int32_t dir = days > 0 ? 1 : -1;
// Grab current year
Int32 year = m_Year;
int32_t year = m_Year;
// Calculate the days in the current year
Int32 diy = Chrono::DaysInYear(year);
int32_t diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
// Calculate the day of year
Int32 doy = GetDayOfYear() + days;
int32_t doy = GetDayOfYear() + days;
// Calculate the resulting years
while (doy > diy || doy < 0)
{
doy -= diy * dir;
year += dir;
diy = Chrono::DaysInYear(year);
diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
}
// Replicate the current date
Datetime dt(*this);
// Set the obtained year
dt.SetYear(year);
dt.SetYear(static_cast< uint16_t >(year));
// Set the obtained day of year
dt.SetDayOfYear(doy);
dt.SetDayOfYear(static_cast< uint16_t >(doy));
// Return the resulted date
return dt;
}
// ------------------------------------------------------------------------------------------------
Datetime Datetime::AndHours(Int32 hours)
Datetime Datetime::AndHours(int32_t hours)
{
// Did we even add any hours?
if (!hours)
@ -601,7 +601,7 @@ Datetime Datetime::AndHours(Int32 hours)
return Datetime(*this); // Return the date-time as is
}
// Extract the number of days
Int32 days = static_cast< Int32 >(hours / 24);
auto days = static_cast< int32_t >(hours / 24);
// Extract the number of hours
hours = m_Hour + (hours % 24);
// Are the hours overlapping with the next day?
@ -617,13 +617,13 @@ Datetime Datetime::AndHours(Int32 hours)
dt.AddDays(days);
}
// Assign the resulted hours
dt.m_Hour = (hours % 24);
dt.m_Hour = static_cast< uint8_t >(hours % 24);
// Return the result
return dt;
}
// ------------------------------------------------------------------------------------------------
Datetime Datetime::AndMinutes(Int32 minutes)
Datetime Datetime::AndMinutes(int32_t minutes)
{
// Did we even added any minutes?
if (!minutes)
@ -631,7 +631,7 @@ Datetime Datetime::AndMinutes(Int32 minutes)
return Datetime(*this); // Return the date-time as is
}
// Extract the number of hours
Int32 hours = static_cast< Int32 >(minutes / 60);
auto hours = static_cast< int32_t >(minutes / 60);
// Extract the number of minutes
minutes = m_Minute + (minutes % 60);
// Are the minutes overlapping with the next hour?
@ -647,13 +647,13 @@ Datetime Datetime::AndMinutes(Int32 minutes)
dt.AddHours(hours);
}
// Assign the resulted minutes
dt.m_Minute = (minutes % 60);
dt.m_Minute = static_cast< uint8_t >(minutes % 60);
// Return the result
return dt;
}
// ------------------------------------------------------------------------------------------------
Datetime Datetime::AndSeconds(Int32 seconds)
Datetime Datetime::AndSeconds(int32_t seconds)
{
// Did we even added any seconds?
if (!seconds)
@ -661,7 +661,7 @@ Datetime Datetime::AndSeconds(Int32 seconds)
return Datetime(*this); // Return the date-time as is
}
// Extract the number of minutes
Int32 minutes = static_cast< Int32 >(seconds / 60);
auto minutes = static_cast< int32_t >(seconds / 60);
// Extract the number of seconds
seconds = m_Second + (seconds % 60);
// Are the seconds overlapping with the next minute?
@ -677,13 +677,13 @@ Datetime Datetime::AndSeconds(Int32 seconds)
dt.AddMinutes(minutes);
}
// Assign the resulted seconds
dt.m_Second = (seconds % 60);
dt.m_Second = static_cast< uint8_t >(seconds % 60);
// Return the result
return dt;
}
// ------------------------------------------------------------------------------------------------
Datetime Datetime::AndMilliseconds(Int32 milliseconds)
Datetime Datetime::AndMilliseconds(int32_t milliseconds)
{
// Did we even added any milliseconds?
if (!milliseconds)
@ -691,7 +691,7 @@ Datetime Datetime::AndMilliseconds(Int32 milliseconds)
return Datetime(*this); // Return the date-time as is
}
// Extract the number of seconds
Int32 seconds = static_cast< Int32 >(milliseconds / 1000);
auto seconds = static_cast< int32_t >(milliseconds / 1000);
// Extract the number of milliseconds
milliseconds = m_Millisecond + (milliseconds % 1000);
// Are the milliseconds overlapping with the next second?
@ -707,7 +707,7 @@ Datetime Datetime::AndMilliseconds(Int32 milliseconds)
dt.AddSeconds(seconds);
}
// Assign the resulted milliseconds
dt.m_Millisecond = (milliseconds % 1000);
dt.m_Millisecond = static_cast< uint16_t >(milliseconds % 1000);
// Return the result
return dt;
}
@ -728,19 +728,19 @@ Time Datetime::GetTime() const
Timestamp Datetime::GetTimestamp() const
{
// Calculate the current day of the year
Int32 days = Chrono::DayOfYear(m_Year, m_Month, m_Day);
int32_t days = Chrono::DayOfYear(m_Year, m_Month, m_Day);
// Calculate all days till the current year
for (Int32 year = 0; year < m_Year; --year)
for (int32_t year = 0; year < m_Year; --year)
{
days += Chrono::DaysInYear(year);
days += Chrono::DaysInYear(static_cast< uint16_t >(year));
}
// Calculate the microseconds in the resulted days
Int64 ms = static_cast< Int64 >(days * 86400000000LL);
auto ms = static_cast< int64_t >(days * 86400000000LL);
// Calculate the microseconds in the current time
ms += static_cast< Int64 >(m_Hour * 3600000000LL);
ms += static_cast< Int64 >(m_Minute * 60000000L);
ms += static_cast< Int64 >(m_Second * 1000000L);
ms += static_cast< Int64 >(m_Millisecond * 1000L);
ms += static_cast< int64_t >(m_Hour * 3600000000LL);
ms += static_cast< int64_t >(m_Minute * 60000000L);
ms += static_cast< int64_t >(m_Second * 1000000L);
ms += static_cast< int64_t >(m_Millisecond * 1000L);
// Return the resulted timestamp
return Timestamp(ms);
}
@ -752,13 +752,13 @@ void Register_ChronoDatetime(HSQUIRRELVM vm, Table & /*cns*/)
Class< Datetime >(vm, Typename::Str)
// Constructors
.Ctor()
.Ctor< Uint16 >()
.Ctor< Uint16, Uint8 >()
.Ctor< Uint16, Uint8, Uint8 >()
.Ctor< Uint16, Uint8, Uint8, Uint8 >()
.Ctor< Uint16, Uint8, Uint8, Uint8, Uint8 >()
.Ctor< Uint16, Uint8, Uint8, Uint8, Uint8, Uint8 >()
.Ctor< Uint16, Uint8, Uint8, Uint8, Uint8, Uint8, Uint16 >()
.Ctor< uint16_t >()
.Ctor< uint16_t, uint8_t >()
.Ctor< uint16_t, uint8_t, uint8_t >()
.Ctor< uint16_t, uint8_t, uint8_t, uint8_t >()
.Ctor< uint16_t, uint8_t, uint8_t, uint8_t, uint8_t >()
.Ctor< uint16_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t >()
.Ctor< uint16_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint16_t >()
// Static Properties
.SetStaticValue(_SC("GlobalDelimiter"), &Datetime::Delimiter)
.SetStaticValue(_SC("GlobalDateDelim"), &Datetime::DateDelim)
@ -809,13 +809,13 @@ void Register_ChronoDatetime(HSQUIRRELVM vm, Table & /*cns*/)
.Func(_SC("AndMillis"), &Datetime::AndMilliseconds)
.Func(_SC("AndMilliseconds"), &Datetime::AndMilliseconds)
// Overloaded Methods
.Overload< void (Datetime::*)(Uint16) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(Uint16, Uint8) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(Uint16, Uint8, Uint8) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(Uint16, Uint8, Uint8, Uint8) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(Uint16, Uint8, Uint8, Uint8, Uint8) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(Uint16, Uint8, Uint8, Uint8, Uint8, Uint8) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(Uint16, Uint8, Uint8, Uint8, Uint8, Uint8, Uint16) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(uint16_t) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(uint16_t, uint8_t) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(uint16_t, uint8_t, uint8_t) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(uint16_t, uint8_t, uint8_t, uint8_t) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(uint16_t, uint8_t, uint8_t, uint8_t, uint8_t) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(uint16_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t) >(_SC("Set"), &Datetime::Set)
.Overload< void (Datetime::*)(uint16_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint16_t) >(_SC("Set"), &Datetime::Set)
);
}

View File

@ -21,15 +21,15 @@ public:
private:
// ------------------------------------------------------------------------------------------------
Uint16 m_Year; // Year
Uint8 m_Month; // Month
Uint8 m_Day; // Day
uint16_t m_Year{}; // Year
uint8_t m_Month{}; // Month
uint8_t m_Day{}; // Day
// ------------------------------------------------------------------------------------------------
Uint8 m_Hour; // Hour
Uint8 m_Minute; // Minute
Uint8 m_Second; // Second
Uint16 m_Millisecond; // Millisecond
uint8_t m_Hour{}; // Hour
uint8_t m_Minute{}; // Minute
uint8_t m_Second{}; // Second
uint16_t m_Millisecond{}; // Millisecond
// ------------------------------------------------------------------------------------------------
SQChar m_Delimiter; // Date and time delimiter when generating strings.
@ -41,7 +41,7 @@ protected:
/* ------------------------------------------------------------------------------------------------
* Compare the values of two instances.
*/
Int32 Compare(const Datetime & o) const;
SQMOD_NODISCARD int32_t Compare(const Datetime & o) const;
public:
@ -64,9 +64,9 @@ public:
}
/* ------------------------------------------------------------------------------------------------
* Speciffic year constructor.
* Specific year constructor.
*/
Datetime(Uint16 year)
explicit Datetime(uint16_t year)
: m_Delimiter(Delimiter)
, m_DateDelim(DateDelim)
, m_TimeDelim(TimeDelim)
@ -75,9 +75,9 @@ public:
}
/* ------------------------------------------------------------------------------------------------
* Speciffic year and month constructor.
* Specific year and month constructor.
*/
Datetime(Uint16 year, Uint8 month)
Datetime(uint16_t year, uint8_t month)
: m_Delimiter(Delimiter)
, m_DateDelim(DateDelim)
, m_TimeDelim(TimeDelim)
@ -86,9 +86,9 @@ public:
}
/* ------------------------------------------------------------------------------------------------
* Speciffic date constructor.
* Specific date constructor.
*/
Datetime(Uint16 year, Uint8 month, Uint8 day)
Datetime(uint16_t year, uint8_t month, uint8_t day)
: m_Delimiter(Delimiter)
, m_DateDelim(DateDelim)
, m_TimeDelim(TimeDelim)
@ -97,9 +97,9 @@ public:
}
/* ------------------------------------------------------------------------------------------------
* Speciffic date and hour constructor.
* Specific date and hour constructor.
*/
Datetime(Uint16 year, Uint8 month, Uint8 day, Uint8 hour)
Datetime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour)
: m_Delimiter(Delimiter)
, m_DateDelim(DateDelim)
, m_TimeDelim(TimeDelim)
@ -108,9 +108,9 @@ public:
}
/* ------------------------------------------------------------------------------------------------
* Speciffic date, hour and minute constructor.
* Specific date, hour and minute constructor.
*/
Datetime(Uint16 year, Uint8 month, Uint8 day, Uint8 hour, Uint8 minute)
Datetime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute)
: m_Delimiter(Delimiter)
, m_DateDelim(DateDelim)
, m_TimeDelim(TimeDelim)
@ -119,9 +119,9 @@ public:
}
/* ------------------------------------------------------------------------------------------------
* Speciffic date and time constructor.
* Specific date and time constructor.
*/
Datetime(Uint16 year, Uint8 month, Uint8 day, Uint8 hour, Uint8 minute, Uint8 second)
Datetime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
: m_Delimiter(Delimiter)
, m_DateDelim(DateDelim)
, m_TimeDelim(TimeDelim)
@ -130,9 +130,9 @@ public:
}
/* ------------------------------------------------------------------------------------------------
* Speciffic date and precise time constructor.
* Specific date and precise time constructor.
*/
Datetime(Uint16 year, Uint8 month, Uint8 day, Uint8 hour, Uint8 minute, Uint8 second, Uint16 millisecond)
Datetime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint16_t millisecond)
: m_Delimiter(Delimiter)
, m_DateDelim(DateDelim)
, m_TimeDelim(TimeDelim)
@ -236,7 +236,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Datetime & o) const
SQMOD_NODISCARD int32_t Cmp(const Datetime & o) const
{
return Compare(o);
}
@ -244,12 +244,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year)
void Set(uint16_t year)
{
Set(year, m_Month, m_Day, m_Hour, m_Minute, m_Second, m_Millisecond);
}
@ -257,7 +257,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year, Uint8 month)
void Set(uint16_t year, uint8_t month)
{
Set(year, month, m_Day, m_Hour, m_Minute, m_Second, m_Millisecond);
}
@ -265,7 +265,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year, Uint8 month, Uint8 day)
void Set(uint16_t year, uint8_t month, uint8_t day)
{
Set(year, month, day, m_Hour, m_Minute, m_Second, m_Millisecond);
}
@ -273,7 +273,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year, Uint8 month, Uint8 day, Uint8 hour)
void Set(uint16_t year, uint8_t month, uint8_t day, uint8_t hour)
{
Set(year, month, day, hour, m_Minute, m_Second, m_Millisecond);
}
@ -281,7 +281,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year, Uint8 month, Uint8 day, Uint8 hour, Uint8 minute)
void Set(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute)
{
Set(year, month, day, hour, minute, m_Second, m_Millisecond);
}
@ -289,7 +289,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year, Uint8 month, Uint8 day, Uint8 hour, Uint8 minute, Uint8 second)
void Set(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
{
Set(year, month, day, hour, minute, second, m_Millisecond);
}
@ -297,12 +297,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint16 year, Uint8 month, Uint8 day, Uint8 hour, Uint8 minute, Uint8 second, Uint16 millisecond);
void Set(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint16_t millisecond);
/* ------------------------------------------------------------------------------------------------
* Retrieve the local delimiter character.
*/
SQChar GetDelimiter() const
SQMOD_NODISCARD SQChar GetDelimiter() const
{
return m_Delimiter;
}
@ -318,7 +318,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the local date delimiter character.
*/
SQChar GetDateDelim() const
SQMOD_NODISCARD SQChar GetDateDelim() const
{
return m_DateDelim;
}
@ -334,7 +334,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the local time delimiter character.
*/
SQChar GetTimeDelim() const
SQMOD_NODISCARD SQChar GetTimeDelim() const
{
return m_TimeDelim;
}
@ -350,7 +350,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the values as a string.
*/
CSStr GetStr() const
SQMOD_NODISCARD String GetStr() const
{
return ToString();
}
@ -358,12 +358,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Extract the values from a string.
*/
void SetStr(CSStr str);
void SetStr(const SQChar * str);
/* ------------------------------------------------------------------------------------------------
* Retrieve the day component.
*/
Uint16 GetDayOfYear() const
SQMOD_NODISCARD uint16_t GetDayOfYear() const
{
return Chrono::DayOfYear(m_Year, m_Month, m_Day);
}
@ -371,12 +371,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the day component.
*/
void SetDayOfYear(Uint16 doy);
void SetDayOfYear(uint16_t doy);
/* ------------------------------------------------------------------------------------------------
* Retrieve the year component.
*/
Uint16 GetYear() const
SQMOD_NODISCARD uint16_t GetYear() const
{
return m_Year;
}
@ -384,12 +384,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the year component.
*/
void SetYear(Uint16 year);
void SetYear(uint16_t year);
/* ------------------------------------------------------------------------------------------------
* Retrieve the month component.
*/
Uint8 GetMonth() const
SQMOD_NODISCARD uint8_t GetMonth() const
{
return m_Month;
}
@ -397,12 +397,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the month component.
*/
void SetMonth(Uint8 month);
void SetMonth(uint8_t month);
/* ------------------------------------------------------------------------------------------------
* Retrieve the day component.
*/
Uint8 GetDay() const
SQMOD_NODISCARD uint8_t GetDay() const
{
return m_Day;
}
@ -410,12 +410,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the day component.
*/
void SetDay(Uint8 day);
void SetDay(uint8_t day);
/* ------------------------------------------------------------------------------------------------
* Retrieve the hour component.
*/
Uint8 GetHour() const
SQMOD_NODISCARD uint8_t GetHour() const
{
return m_Hour;
}
@ -423,12 +423,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the hour component.
*/
void SetHour(Uint8 hour);
void SetHour(uint8_t hour);
/* ------------------------------------------------------------------------------------------------
* Retrieve the minute component.
*/
Uint8 GetMinute() const
SQMOD_NODISCARD uint8_t GetMinute() const
{
return m_Minute;
}
@ -436,12 +436,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the minute component.
*/
void SetMinute(Uint8 minute);
void SetMinute(uint8_t minute);
/* ------------------------------------------------------------------------------------------------
* Retrieve the second component.
*/
Uint8 GetSecond() const
SQMOD_NODISCARD uint8_t GetSecond() const
{
return m_Second;
}
@ -449,12 +449,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the second component.
*/
void SetSecond(Uint8 second);
void SetSecond(uint8_t second);
/* ------------------------------------------------------------------------------------------------
* Retrieve the millisecond component.
*/
Uint16 GetMillisecond() const
SQMOD_NODISCARD uint16_t GetMillisecond() const
{
return m_Millisecond;
}
@ -462,82 +462,82 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the millisecond component.
*/
void SetMillisecond(Uint16 millisecond);
void SetMillisecond(uint16_t millisecond);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of years to the current date.
*/
Datetime & AddYears(Int32 years);
Datetime & AddYears(int32_t years);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of months to the current date.
*/
Datetime & AddMonths(Int32 months);
Datetime & AddMonths(int32_t months);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of days to the current date.
*/
Datetime & AddDays(Int32 days);
Datetime & AddDays(int32_t days);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of hours to the current time.
*/
Datetime & AddHours(Int32 hours);
Datetime & AddHours(int32_t hours);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of minutes to the current time.
*/
Datetime & AddMinutes(Int32 minutes);
Datetime & AddMinutes(int32_t minutes);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of seconds to the current time.
*/
Datetime & AddSeconds(Int32 seconds);
Datetime & AddSeconds(int32_t seconds);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of milliseconds to the current time.
*/
Datetime & AddMilliseconds(Int32 milliseconds);
Datetime & AddMilliseconds(int32_t milliseconds);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of years to obtain a new date.
*/
Datetime AndYears(Int32 years);
SQMOD_NODISCARD Datetime AndYears(int32_t years);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of months to obtain a new date.
*/
Datetime AndMonths(Int32 months);
SQMOD_NODISCARD Datetime AndMonths(int32_t months);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of days to obtain a new date.
*/
Datetime AndDays(Int32 days);
SQMOD_NODISCARD Datetime AndDays(int32_t days);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of hours to obtain a new time.
*/
Datetime AndHours(Int32 hours);
SQMOD_NODISCARD Datetime AndHours(int32_t hours);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of minutes to obtain a new time.
*/
Datetime AndMinutes(Int32 minutes);
SQMOD_NODISCARD Datetime AndMinutes(int32_t minutes);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of seconds to obtain a new time.
*/
Datetime AndSeconds(Int32 seconds);
SQMOD_NODISCARD Datetime AndSeconds(int32_t seconds);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of milliseconds to obtain a new time.
*/
Datetime AndMilliseconds(Int32 milliseconds);
SQMOD_NODISCARD Datetime AndMilliseconds(int32_t milliseconds);
/* ------------------------------------------------------------------------------------------------
* See whether the associated year is a leap year.
*/
bool IsThisLeapYear() const
SQMOD_NODISCARD bool IsThisLeapYear() const
{
return Chrono::IsLeapYear(m_Year);
}
@ -545,7 +545,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the number of days in the associated year.
*/
Uint16 GetYearDays() const
SQMOD_NODISCARD uint16_t GetYearDays() const
{
return Chrono::DaysInYear(m_Year);
}
@ -553,7 +553,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the number of days in the associated month.
*/
Uint8 GetMonthDays() const
SQMOD_NODISCARD uint8_t GetMonthDays() const
{
return Chrono::DaysInMonth(m_Year, m_Month);
}
@ -561,17 +561,17 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the date from this date-time instance.
*/
Date GetDate() const;
SQMOD_NODISCARD Date GetDate() const;
/* ------------------------------------------------------------------------------------------------
* Retrieve the time from this date-time instance.
*/
Time GetTime() const;
SQMOD_NODISCARD Time GetTime() const;
/* ------------------------------------------------------------------------------------------------
* Convert this date-time instance to a time-stamp.
*/
Timestamp GetTimestamp() const;
SQMOD_NODISCARD Timestamp GetTimestamp() const;
};
} // Namespace:: SqMod

View File

@ -1,28 +1,26 @@
// ------------------------------------------------------------------------------------------------
#include "Library/Chrono/Time.hpp"
#include "Library/Chrono/Date.hpp"
#include "Library/Chrono/Datetime.hpp"
#include "Library/Chrono/Timestamp.hpp"
#include "Base/Shared.hpp"
#include "Core/Utility.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqTime"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqTime"))
// ------------------------------------------------------------------------------------------------
SQChar Time::Delimiter = ':';
// ------------------------------------------------------------------------------------------------
Int32 Time::Compare(const Time & o) const
int32_t Time::Compare(const Time & o) const
{
if (m_Hour < o.m_Hour)
{
{ // NOLINT(bugprone-branch-clone)
return -1;
}
else if (m_Hour > o.m_Hour)
{
{ // NOLINT(bugprone-branch-clone)
return 1;
}
else if (m_Minute < o.m_Minute)
@ -80,9 +78,9 @@ Time Time::operator / (const Time & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr Time::ToString() const
String Time::ToString() const
{
return ToStrF("%02u%c%02u%c%02u%c%u",
return fmt::format("{:02}{}{:02}{}{:02}{}{}",
m_Hour, m_Delimiter,
m_Minute, m_Delimiter,
m_Second, m_Delimiter,
@ -90,7 +88,7 @@ CSStr Time::ToString() const
}
// ------------------------------------------------------------------------------------------------
void Time::Set(Uint8 hour, Uint8 minute, Uint8 second, Uint16 millisecond)
void Time::Set(uint8_t hour, uint8_t minute, uint8_t second, uint16_t millisecond)
{
// Is the specified hour within range?
if (hour >= 24)
@ -120,7 +118,7 @@ void Time::Set(Uint8 hour, Uint8 minute, Uint8 second, Uint16 millisecond)
}
// ------------------------------------------------------------------------------------------------
void Time::SetStr(CSStr str)
void Time::SetStr(const SQChar * str)
{
// The format specifications that will be used to scan the string
static SQChar fs[] = _SC(" %u : %u : %u : %u ");
@ -140,19 +138,19 @@ void Time::SetStr(CSStr str)
fs[9] = m_Delimiter;
fs[14] = m_Delimiter;
// The sscanf function requires at least 32 bit integers
Uint32 hour = 0, minute = 0, second = 0, milli = 0;
uint32_t hour = 0, minute = 0, second = 0, milli = 0;
// Attempt to extract the component values from the specified string
sscanf(str, fs, &hour, &minute, &second, &milli);
// Clamp the extracted values to the boundaries of associated type and assign them
Set(ClampL< Uint32, Uint8 >(hour),
ClampL< Uint32, Uint8 >(minute),
ClampL< Uint32, Uint8 >(second),
ClampL< Uint32, Uint16 >(milli)
Set(ClampL< uint32_t, uint8_t >(hour),
ClampL< uint32_t, uint8_t >(minute),
ClampL< uint32_t, uint8_t >(second),
ClampL< uint32_t, uint16_t >(milli)
);
}
// ------------------------------------------------------------------------------------------------
void Time::SetHour(Uint8 hour)
void Time::SetHour(uint8_t hour)
{
// Is the specified hour within range?
if (hour >= 24)
@ -164,7 +162,7 @@ void Time::SetHour(Uint8 hour)
}
// ------------------------------------------------------------------------------------------------
void Time::SetMinute(Uint8 minute)
void Time::SetMinute(uint8_t minute)
{
// Is the specified minute within range?
if (minute >= 60)
@ -176,7 +174,7 @@ void Time::SetMinute(Uint8 minute)
}
// ------------------------------------------------------------------------------------------------
void Time::SetSecond(Uint8 second)
void Time::SetSecond(uint8_t second)
{
// Is the specified second within range?
if (second >= 60)
@ -188,7 +186,7 @@ void Time::SetSecond(Uint8 second)
}
// ------------------------------------------------------------------------------------------------
void Time::SetMillisecond(Uint16 millisecond)
void Time::SetMillisecond(uint16_t millisecond)
{
// Is the specified millisecond within range?
if (millisecond >= 1000)
@ -200,7 +198,7 @@ void Time::SetMillisecond(Uint16 millisecond)
}
// ------------------------------------------------------------------------------------------------
Time & Time::AddHours(Int32 hours)
Time & Time::AddHours(int32_t hours)
{
// Did we even add any hours?
if (hours)
@ -215,13 +213,13 @@ Time & Time::AddHours(Int32 hours)
}
// ------------------------------------------------------------------------------------------------
Time & Time::AddMinutes(Int32 minutes)
Time & Time::AddMinutes(int32_t minutes)
{
// Did we even add any minutes?
if (minutes)
{
// Extract the number of hours
Int32 hours = static_cast< Int32 >(minutes / 60);
auto hours = static_cast< int32_t >(minutes / 60);
// Extract the number of minutes
m_Minute += (minutes % 60);
// Are the minutes overlapping with the next hour?
@ -243,13 +241,13 @@ Time & Time::AddMinutes(Int32 minutes)
}
// ------------------------------------------------------------------------------------------------
Time & Time::AddSeconds(Int32 seconds)
Time & Time::AddSeconds(int32_t seconds)
{
// Did we even add any seconds?
if (seconds)
{
// Extract the number of minutes
Int32 minutes = static_cast< Int32 >(seconds / 60);
auto minutes = static_cast< int32_t >(seconds / 60);
// Extract the number of seconds
m_Second += (seconds % 60);
// Are the seconds overlapping with the next minute?
@ -271,13 +269,13 @@ Time & Time::AddSeconds(Int32 seconds)
}
// ------------------------------------------------------------------------------------------------
Time & Time::AddMilliseconds(Int32 milliseconds)
Time & Time::AddMilliseconds(int32_t milliseconds)
{
// Did we even add any milliseconds?
if (milliseconds)
{
// Extract the number of seconds
Int32 seconds = static_cast< Int32 >(milliseconds / 1000);
auto seconds = static_cast< int32_t >(milliseconds / 1000);
// Extract the number of milliseconds
m_Millisecond += (milliseconds / 1000);
// Are the milliseconds overlapping with the next second?
@ -299,19 +297,19 @@ Time & Time::AddMilliseconds(Int32 milliseconds)
}
// ------------------------------------------------------------------------------------------------
Time Time::AndHours(Int32 hours)
Time Time::AndHours(int32_t hours)
{
// Did we even add any hours?
if (hours)
{
return Time((m_Hour + (hours % 24)) % 24, m_Minute, m_Second, m_Millisecond);
return Time(static_cast< uint8_t >((m_Hour + (hours % 24)) % 24), m_Minute, m_Second, m_Millisecond);
}
// Return the time as is
return Time(*this);
}
// ------------------------------------------------------------------------------------------------
Time Time::AndMinutes(Int32 minutes)
Time Time::AndMinutes(int32_t minutes)
{
// Did we even added any minutes?
if (!minutes)
@ -319,7 +317,7 @@ Time Time::AndMinutes(Int32 minutes)
return Time(*this); // Return the time as is
}
// Extract the number of hours
Int32 hours = static_cast< Int32 >(minutes / 60);
auto hours = static_cast< int32_t >(minutes / 60);
// Extract the number of minutes
minutes = m_Minute + (minutes % 60);
// Are the minutes overlapping with the next hour?
@ -335,13 +333,13 @@ Time Time::AndMinutes(Int32 minutes)
t.AddHours(hours);
}
// Assign the resulted minutes
t.m_Minute = (minutes % 60);
t.m_Minute = static_cast< uint8_t >(minutes % 60);
// Return the result
return t;
}
// ------------------------------------------------------------------------------------------------
Time Time::AndSeconds(Int32 seconds)
Time Time::AndSeconds(int32_t seconds)
{
// Did we even added any seconds?
if (!seconds)
@ -349,7 +347,7 @@ Time Time::AndSeconds(Int32 seconds)
return Time(*this); // Return the time as is
}
// Extract the number of minutes
Int32 minutes = static_cast< Int32 >(seconds / 60);
auto minutes = static_cast< int32_t >(seconds / 60);
// Extract the number of seconds
seconds = m_Second + (seconds % 60);
// Are the seconds overlapping with the next minute?
@ -365,13 +363,13 @@ Time Time::AndSeconds(Int32 seconds)
t.AddMinutes(minutes);
}
// Assign the resulted seconds
t.m_Second = (seconds % 60);
t.m_Second = static_cast< uint8_t >(seconds % 60);
// Return the result
return t;
}
// ------------------------------------------------------------------------------------------------
Time Time::AndMilliseconds(Int32 milliseconds)
Time Time::AndMilliseconds(int32_t milliseconds)
{
// Did we even added any milliseconds?
if (!milliseconds)
@ -379,7 +377,7 @@ Time Time::AndMilliseconds(Int32 milliseconds)
return Time(*this); // Return the time as is
}
// Extract the number of seconds
Int32 seconds = static_cast< Int32 >(milliseconds / 1000);
auto seconds = static_cast< int32_t >(milliseconds / 1000);
// Extract the number of milliseconds
milliseconds = m_Millisecond + (milliseconds % 1000);
// Are the milliseconds overlapping with the next second?
@ -395,7 +393,7 @@ Time Time::AndMilliseconds(Int32 milliseconds)
t.AddSeconds(seconds);
}
// Assign the resulted milliseconds
t.m_Millisecond = (milliseconds % 1000);
t.m_Millisecond = static_cast< uint16_t >(milliseconds % 1000);
// Return the result
return t;
}
@ -404,10 +402,10 @@ Time Time::AndMilliseconds(Int32 milliseconds)
Timestamp Time::GetTimestamp() const
{
// Calculate the microseconds in the current time
Int64 ms = static_cast< Int64 >(m_Hour * 3600000000LL);
ms += static_cast< Int64 >(m_Minute * 60000000L);
ms += static_cast< Int64 >(m_Second * 1000000L);
ms += static_cast< Int64 >(m_Millisecond * 1000L);
auto ms = static_cast< int64_t >(m_Hour * 3600000000LL);
ms += static_cast< int64_t >(m_Minute * 60000000L);
ms += static_cast< int64_t >(m_Second * 1000000L);
ms += static_cast< int64_t >(m_Millisecond * 1000L);
// Return the resulted timestamp
return Timestamp(ms);
}
@ -419,10 +417,10 @@ void Register_ChronoTime(HSQUIRRELVM vm, Table & /*cns*/)
Class< Time >(vm, Typename::Str)
// Constructors
.Ctor()
.Ctor< Uint8 >()
.Ctor< Uint8, Uint8 >()
.Ctor< Uint8, Uint8, Uint8 >()
.Ctor< Uint8, Uint8, Uint8, Uint16 >()
.Ctor< uint8_t >()
.Ctor< uint8_t, uint8_t >()
.Ctor< uint8_t, uint8_t, uint8_t >()
.Ctor< uint8_t, uint8_t, uint8_t, uint16_t >()
// Static Properties
.SetStaticValue(_SC("GlobalDelimiter"), &Time::Delimiter)
// Core Meta-methods
@ -454,10 +452,10 @@ void Register_ChronoTime(HSQUIRRELVM vm, Table & /*cns*/)
.Func(_SC("AndMillis"), &Time::AndMilliseconds)
.Func(_SC("AndMilliseconds"), &Time::AndMilliseconds)
// Overloaded Methods
.Overload< void (Time::*)(Uint8) >(_SC("Set"), &Time::Set)
.Overload< void (Time::*)(Uint8, Uint8) >(_SC("Set"), &Time::Set)
.Overload< void (Time::*)(Uint8, Uint8, Uint8) >(_SC("Set"), &Time::Set)
.Overload< void (Time::*)(Uint8, Uint8, Uint8, Uint16) >(_SC("Set"), &Time::Set)
.Overload< void (Time::*)(uint8_t) >(_SC("Set"), &Time::Set)
.Overload< void (Time::*)(uint8_t, uint8_t) >(_SC("Set"), &Time::Set)
.Overload< void (Time::*)(uint8_t, uint8_t, uint8_t) >(_SC("Set"), &Time::Set)
.Overload< void (Time::*)(uint8_t, uint8_t, uint8_t, uint16_t) >(_SC("Set"), &Time::Set)
);
}

View File

@ -21,15 +21,15 @@ protected:
/* ------------------------------------------------------------------------------------------------
* Compare the values of two instances.
*/
Int32 Compare(const Time & o) const;
SQMOD_NODISCARD int32_t Compare(const Time & o) const;
private:
// ------------------------------------------------------------------------------------------------
Uint8 m_Hour; // Hour
Uint8 m_Minute; // Minute
Uint8 m_Second; // Second
Uint16 m_Millisecond; // Millisecond
uint8_t m_Hour{}; // Hour
uint8_t m_Minute{}; // Minute
uint8_t m_Second{}; // Second
uint16_t m_Millisecond{}; // Millisecond
// ------------------------------------------------------------------------------------------------
SQChar m_Delimiter; // Component delimiter when generating strings.
@ -52,7 +52,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Base constructor.
*/
Time(Uint8 hour)
explicit Time(uint8_t hour)
: m_Delimiter(Delimiter)
{
Set(hour, 0, 0, 0);
@ -61,7 +61,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Base constructor.
*/
Time(Uint8 hour, Uint8 minute)
Time(uint8_t hour, uint8_t minute)
: m_Delimiter(Delimiter)
{
Set(hour, minute, 0, 0);
@ -70,7 +70,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Base constructor.
*/
Time(Uint8 hour, Uint8 minute, Uint8 second)
Time(uint8_t hour, uint8_t minute, uint8_t second)
: m_Delimiter(Delimiter)
{
Set(hour, minute, second, 0);
@ -79,7 +79,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Base constructor.
*/
Time(Uint8 hour, Uint8 minute, Uint8 second, Uint16 millisecond)
Time(uint8_t hour, uint8_t minute, uint8_t second, uint16_t millisecond)
: m_Delimiter(Delimiter)
{
Set(hour, minute, second, millisecond);
@ -88,7 +88,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* String constructor.
*/
Time(CSStr str)
explicit Time(const SQChar * str)
: m_Delimiter(Delimiter)
{
SetStr(str);
@ -190,7 +190,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to compare two instances of this type.
*/
Int32 Cmp(const Time & o) const
SQMOD_NODISCARD int32_t Cmp(const Time & o) const
{
return Compare(o);
}
@ -198,12 +198,12 @@ public:
/* --------------------------------------------------------------------------------------------
* Used by the script engine to convert an instance of this type to a string.
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint8 hour)
void Set(uint8_t hour)
{
Set(hour, m_Minute, m_Second, m_Millisecond);
}
@ -211,7 +211,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint8 hour, Uint8 minute)
void Set(uint8_t hour, uint8_t minute)
{
Set(hour, minute, m_Second, m_Millisecond);
}
@ -219,7 +219,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint8 hour, Uint8 minute, Uint8 second)
void Set(uint8_t hour, uint8_t minute, uint8_t second)
{
Set(hour, minute, second, m_Millisecond);
}
@ -227,12 +227,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Assign the specified values.
*/
void Set(Uint8 hour, Uint8 minute, Uint8 second, Uint16 millisecond);
void Set(uint8_t hour, uint8_t minute, uint8_t second, uint16_t millisecond);
/* ------------------------------------------------------------------------------------------------
* Retrieve the local delimiter character.
*/
SQChar GetDelimiter() const
SQMOD_NODISCARD SQChar GetDelimiter() const
{
return m_Delimiter;
}
@ -248,7 +248,7 @@ public:
/* ------------------------------------------------------------------------------------------------
* Retrieve the values as a string.
*/
CSStr GetStr() const
SQMOD_NODISCARD String GetStr() const
{
return ToString();
}
@ -256,12 +256,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Extract the values from a string.
*/
void SetStr(CSStr str);
void SetStr(const SQChar * str);
/* ------------------------------------------------------------------------------------------------
* Retrieve the hour component.
*/
Uint8 GetHour() const
SQMOD_NODISCARD uint8_t GetHour() const
{
return m_Hour;
}
@ -269,12 +269,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the hour component.
*/
void SetHour(Uint8 hour);
void SetHour(uint8_t hour);
/* ------------------------------------------------------------------------------------------------
* Retrieve the minute component.
*/
Uint8 GetMinute() const
SQMOD_NODISCARD uint8_t GetMinute() const
{
return m_Minute;
}
@ -282,12 +282,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the minute component.
*/
void SetMinute(Uint8 minute);
void SetMinute(uint8_t minute);
/* ------------------------------------------------------------------------------------------------
* Retrieve the second component.
*/
Uint8 GetSecond() const
SQMOD_NODISCARD uint8_t GetSecond() const
{
return m_Second;
}
@ -295,12 +295,12 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the second component.
*/
void SetSecond(Uint8 second);
void SetSecond(uint8_t second);
/* ------------------------------------------------------------------------------------------------
* Retrieve the millisecond component.
*/
Uint16 GetMillisecond() const
SQMOD_NODISCARD uint16_t GetMillisecond() const
{
return m_Millisecond;
}
@ -308,52 +308,52 @@ public:
/* ------------------------------------------------------------------------------------------------
* Modify the millisecond component.
*/
void SetMillisecond(Uint16 millisecond);
void SetMillisecond(uint16_t millisecond);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of hours to the current time.
*/
Time & AddHours(Int32 hours);
Time & AddHours(int32_t hours);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of minutes to the current time.
*/
Time & AddMinutes(Int32 minutes);
Time & AddMinutes(int32_t minutes);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of seconds to the current time.
*/
Time & AddSeconds(Int32 seconds);
Time & AddSeconds(int32_t seconds);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of milliseconds to the current time.
*/
Time & AddMilliseconds(Int32 milliseconds);
Time & AddMilliseconds(int32_t milliseconds);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of hours to obtain a new time.
*/
Time AndHours(Int32 hours);
SQMOD_NODISCARD Time AndHours(int32_t hours);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of minutes to obtain a new time.
*/
Time AndMinutes(Int32 minutes);
SQMOD_NODISCARD Time AndMinutes(int32_t minutes);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of seconds to obtain a new time.
*/
Time AndSeconds(Int32 seconds);
SQMOD_NODISCARD Time AndSeconds(int32_t seconds);
/* ------------------------------------------------------------------------------------------------
* Add the specified amount of milliseconds to obtain a new time.
*/
Time AndMilliseconds(Int32 milliseconds);
SQMOD_NODISCARD Time AndMilliseconds(int32_t milliseconds);
/* ------------------------------------------------------------------------------------------------
* Convert this time instance to a time-stamp.
*/
Timestamp GetTimestamp() const;
SQMOD_NODISCARD Timestamp GetTimestamp() const;
};
} // Namespace:: SqMod

View File

@ -1,13 +1,12 @@
// ------------------------------------------------------------------------------------------------
#include "Library/Chrono/Timer.hpp"
#include "Library/Chrono/Timestamp.hpp"
#include "Base/Shared.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqTimer"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqTimer"))
// ------------------------------------------------------------------------------------------------
Timer::Timer()
@ -17,7 +16,7 @@ Timer::Timer()
}
// ------------------------------------------------------------------------------------------------
Int32 Timer::Cmp(const Timer & o) const
int32_t Timer::Cmp(const Timer & o) const
{
if (m_Timestamp == o.m_Timestamp)
return 0;
@ -28,9 +27,9 @@ Int32 Timer::Cmp(const Timer & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr Timer::ToString() const
String Timer::ToString() const
{
return ToStrF("%lld", m_Timestamp);
return fmt::format("{}", m_Timestamp);
}
// ------------------------------------------------------------------------------------------------
@ -42,15 +41,15 @@ void Timer::Reset()
// ------------------------------------------------------------------------------------------------
Timestamp Timer::Restart()
{
const Int64 now = Chrono::GetCurrentSysTime(), elapsed = now - m_Timestamp;
const int64_t now = Chrono::GetCurrentSysTime(), elapsed = now - m_Timestamp;
m_Timestamp = now;
return Timestamp(elapsed);
}
// ------------------------------------------------------------------------------------------------
Int64 Timer::RestartRaw()
int64_t Timer::RestartRaw()
{
const Int64 now = Chrono::GetCurrentSysTime(), elapsed = now - m_Timestamp;
const int64_t now = Chrono::GetCurrentSysTime(), elapsed = now - m_Timestamp;
m_Timestamp = now;
return elapsed;
}
@ -62,7 +61,7 @@ Timestamp Timer::GetElapsedTime() const
}
// ------------------------------------------------------------------------------------------------
Int64 Timer::GetElapsedTimeRaw() const
int64_t Timer::GetElapsedTimeRaw() const
{
return (Chrono::GetCurrentSysTime() - m_Timestamp);
}

View File

@ -14,7 +14,7 @@ class Timer
/* --------------------------------------------------------------------------------------------
*
*/
Timer(Int64 t)
explicit Timer(int64_t t)
: m_Timestamp(t)
{
/* ... */
@ -30,19 +30,12 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
Timer(const Timer & o)
: m_Timestamp(o.m_Timestamp)
{
/* ... */
}
Timer(const Timer & o) = default;
/* --------------------------------------------------------------------------------------------
*
*/
~Timer()
{
/* ... */
}
~Timer() = default;
/* --------------------------------------------------------------------------------------------
*
@ -56,12 +49,12 @@ public:
/* --------------------------------------------------------------------------------------------
* ...
*/
Int32 Cmp(const Timer & b) const;
SQMOD_NODISCARD int32_t Cmp(const Timer & b) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* --------------------------------------------------------------------------------------------
*
@ -76,22 +69,22 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
Int64 RestartRaw();
int64_t RestartRaw();
/* --------------------------------------------------------------------------------------------
*
*/
Timestamp GetElapsedTime() const;
SQMOD_NODISCARD Timestamp GetElapsedTime() const;
/* --------------------------------------------------------------------------------------------
*
*/
Int64 GetElapsedTimeRaw() const;
SQMOD_NODISCARD int64_t GetElapsedTimeRaw() const;
private:
// --------------------------------------------------------------------------------------------
Int64 m_Timestamp;
int64_t m_Timestamp;
};
} // Namespace:: SqMod

View File

@ -2,15 +2,13 @@
#include "Library/Chrono/Timestamp.hpp"
#include "Library/Chrono/Timer.hpp"
#include "Library/Chrono/Date.hpp"
#include "Library/Chrono/Time.hpp"
#include "Library/Chrono/Datetime.hpp"
#include "Library/Numeric/LongInt.hpp"
#include "Library/Numeric/Long.hpp"
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
SQMODE_DECL_TYPENAME(Typename, _SC("SqTimestamp"))
SQMOD_DECL_TYPENAME(Typename, _SC("SqTimestamp"))
// ------------------------------------------------------------------------------------------------
Timestamp::Timestamp(const SLongInt & t)
@ -20,7 +18,7 @@ Timestamp::Timestamp(const SLongInt & t)
}
// ------------------------------------------------------------------------------------------------
Int32 Timestamp::Cmp(const Timestamp & o) const
int32_t Timestamp::Cmp(const Timestamp & o) const
{
if (m_Timestamp == o.m_Timestamp)
{
@ -37,9 +35,9 @@ Int32 Timestamp::Cmp(const Timestamp & o) const
}
// ------------------------------------------------------------------------------------------------
CSStr Timestamp::ToString() const
String Timestamp::ToString() const
{
return ToStrF("%lld", m_Timestamp);
return fmt::format("{}", m_Timestamp);
}
// ------------------------------------------------------------------------------------------------
@ -55,9 +53,9 @@ SLongInt Timestamp::GetMicroseconds() const
}
// ------------------------------------------------------------------------------------------------
void Timestamp::SetMicroseconds(const SLongInt & ammount)
void Timestamp::SetMicroseconds(const SLongInt & amount)
{
m_Timestamp = ammount.GetNum();
m_Timestamp = amount.GetNum();
}
// ------------------------------------------------------------------------------------------------
@ -67,9 +65,9 @@ SLongInt Timestamp::GetMilliseconds() const
}
// ------------------------------------------------------------------------------------------------
void Timestamp::SetMilliseconds(const SLongInt & ammount)
void Timestamp::SetMilliseconds(const SLongInt & amount)
{
m_Timestamp = (ammount.GetNum() * 1000L);
m_Timestamp = (amount.GetNum() * 1000L);
}
// ------------------------------------------------------------------------------------------------
@ -79,51 +77,51 @@ static Timestamp SqGetEpochTimeNow()
}
// ------------------------------------------------------------------------------------------------
static Timestamp SqGetMicrosecondsRaw(Int64 ammount)
static Timestamp SqGetMicrosecondsRaw(int64_t amount)
{
return Timestamp(ammount);
return Timestamp(amount);
}
// ------------------------------------------------------------------------------------------------
static Timestamp SqGetMicroseconds(const SLongInt & ammount)
static Timestamp SqGetMicroseconds(const SLongInt & amount)
{
return Timestamp(ammount);
return Timestamp(amount);
}
// ------------------------------------------------------------------------------------------------
static Timestamp SqGetMilliseconds(SQInteger ammount)
static Timestamp SqGetMilliseconds(SQInteger amount)
{
return Timestamp(Int64(Int64(ammount) * 1000L));
return Timestamp(int64_t(int64_t(amount) * 1000L));
}
// ------------------------------------------------------------------------------------------------
static Timestamp SqGetSeconds(SQFloat ammount)
static Timestamp SqGetSeconds(SQFloat amount)
{
return Timestamp(Int64(Float64(ammount) * 1000000L));
return Timestamp(int64_t(double(amount) * 1000000L));
}
// ------------------------------------------------------------------------------------------------
static Timestamp SqGetMinutes(SQFloat ammount)
static Timestamp SqGetMinutes(SQFloat amount)
{
return Timestamp(Int64((Float64(ammount) * 60000000L)));
return Timestamp(int64_t((double(amount) * 60000000L)));
}
// ------------------------------------------------------------------------------------------------
static Timestamp SqGetHours(SQFloat ammount)
static Timestamp SqGetHours(SQFloat amount)
{
return Timestamp(Int64(Float64(ammount) * 3600000000LL));
return Timestamp(int64_t(double(amount) * 3600000000LL));
}
// ------------------------------------------------------------------------------------------------
static Timestamp SqGetDays(SQFloat ammount)
static Timestamp SqGetDays(SQFloat amount)
{
return Timestamp(Int64(Float64(ammount) * 86400000000LL));
return Timestamp(int64_t(double(amount) * 86400000000LL));
}
// ------------------------------------------------------------------------------------------------
static Timestamp SqGetYears(SQFloat ammount)
static Timestamp SqGetYears(SQFloat amount)
{
return Timestamp(Int64(Float64(ammount) * 31557600000000LL));
return Timestamp(int64_t(double(amount) * 31557600000000LL));
}
// ================================================================================================
@ -174,7 +172,6 @@ void Register_ChronoTimestamp(HSQUIRRELVM vm, Table & /*cns*/)
.StaticFunc(_SC("GetDays"), &SqGetDays)
.StaticFunc(_SC("GetYears"), &SqGetYears)
);
;
}
} // Namespace:: SqMod

View File

@ -31,7 +31,7 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
Timestamp(Int64 t)
explicit Timestamp(int64_t t)
: m_Timestamp(t)
{
/* ... */
@ -45,19 +45,12 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
Timestamp(const Timestamp & o)
: m_Timestamp(o.m_Timestamp)
{
/* ... */
}
Timestamp(const Timestamp & o) = default;
/* --------------------------------------------------------------------------------------------
*
*/
~Timestamp()
{
/* ... */
}
~Timestamp() = default;
/* --------------------------------------------------------------------------------------------
*
@ -103,12 +96,12 @@ public:
/* --------------------------------------------------------------------------------------------
* ...
*/
Int32 Cmp(const Timestamp & b) const;
SQMOD_NODISCARD int32_t Cmp(const Timestamp & b) const;
/* --------------------------------------------------------------------------------------------
* ...
*/
CSStr ToString() const;
SQMOD_NODISCARD String ToString() const;
/* --------------------------------------------------------------------------------------------
* ...
@ -118,7 +111,7 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
Int64 GetNum() const
SQMOD_NODISCARD int64_t GetNum() const
{
return m_Timestamp;
}
@ -126,17 +119,17 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
SLongInt GetMicroseconds() const;
SQMOD_NODISCARD SLongInt GetMicroseconds() const;
/* --------------------------------------------------------------------------------------------
*
*/
void SetMicroseconds(const SLongInt & ammount);
void SetMicroseconds(const SLongInt & amount);
/* --------------------------------------------------------------------------------------------
*
*/
SQInteger GetMicrosecondsRaw() const
SQMOD_NODISCARD SQInteger GetMicrosecondsRaw() const
{
return SQInteger(m_Timestamp);
}
@ -144,25 +137,25 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
void SetMicrosecondsRaw(SQInteger ammount)
void SetMicrosecondsRaw(SQInteger amount)
{
m_Timestamp = ammount;
m_Timestamp = amount;
}
/* --------------------------------------------------------------------------------------------
*
*/
SLongInt GetMilliseconds() const;
SQMOD_NODISCARD SLongInt GetMilliseconds() const;
/* --------------------------------------------------------------------------------------------
*
*/
void SetMilliseconds(const SLongInt & ammount);
void SetMilliseconds(const SLongInt & amount);
/* --------------------------------------------------------------------------------------------
*
*/
SQInteger GetMillisecondsRaw() const
SQMOD_NODISCARD SQInteger GetMillisecondsRaw() const
{
return SQInteger(m_Timestamp / 1000L);
}
@ -170,31 +163,31 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
void SetMillisecondsRaw(SQInteger ammount)
void SetMillisecondsRaw(SQInteger amount)
{
m_Timestamp = Int64(Int64(ammount) * 1000L);
m_Timestamp = int64_t(int64_t(amount) * 1000L);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQFloat GetSecondsF() const
SQMOD_NODISCARD SQFloat GetSecondsF() const
{
return SQFloat(m_Timestamp / 1000000L);
return static_cast< SQFloat >(static_cast< int64_t >(m_Timestamp / 1000000LL));
}
/* --------------------------------------------------------------------------------------------
*
*/
void SetSecondsF(SQFloat ammount)
void SetSecondsF(SQFloat amount)
{
m_Timestamp = Int64(Float64(ammount) * 1000000L);
m_Timestamp = int64_t(double(amount) * 1000000L);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQInteger GetSecondsI() const
SQMOD_NODISCARD SQInteger GetSecondsI() const
{
return SQInteger(m_Timestamp / 1000000L);
}
@ -202,31 +195,31 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
void SetSecondsI(SQInteger ammount)
void SetSecondsI(SQInteger amount)
{
m_Timestamp = Int64(Int64(ammount) * 1000000L);
m_Timestamp = int64_t(int64_t(amount) * 1000000L);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQFloat GetMinutesF() const
SQMOD_NODISCARD SQFloat GetMinutesF() const
{
return SQFloat(m_Timestamp / 60000000.0f);
return SQFloat(m_Timestamp / 60000000.0);
}
/* --------------------------------------------------------------------------------------------
*
*/
void SetMinutesF(SQFloat ammount)
void SetMinutesF(SQFloat amount)
{
m_Timestamp = Int64(Float64(ammount) * 60000000L);
m_Timestamp = int64_t(double(amount) * 60000000L);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQInteger GetMinutesI() const
SQMOD_NODISCARD SQInteger GetMinutesI() const
{
return SQInteger(m_Timestamp / 60000000L);
}
@ -234,31 +227,31 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
void SetMinutesI(SQInteger ammount)
void SetMinutesI(SQInteger amount)
{
m_Timestamp = Int64(Int64(ammount) * 60000000L);
m_Timestamp = int64_t(int64_t(amount) * 60000000L);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQFloat GetHoursF() const
SQMOD_NODISCARD SQFloat GetHoursF() const
{
return SQFloat(m_Timestamp / 3600000000.0d);
return SQFloat(m_Timestamp / 3600000000.0);
}
/* --------------------------------------------------------------------------------------------
*
*/
void SetHoursF(SQFloat ammount)
void SetHoursF(SQFloat amount)
{
m_Timestamp = Int64(Float64(ammount) * 3600000000LL);
m_Timestamp = int64_t(double(amount) * 3600000000LL);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQInteger GetHoursI() const
SQMOD_NODISCARD SQInteger GetHoursI() const
{
return SQInteger(m_Timestamp / 3600000000LL);
}
@ -266,31 +259,31 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
void SetHoursI(SQInteger ammount)
void SetHoursI(SQInteger amount)
{
m_Timestamp = Int64(Float64(ammount) * 3600000000LL);
m_Timestamp = int64_t(double(amount) * 3600000000LL);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQFloat GetDaysF() const
SQMOD_NODISCARD SQFloat GetDaysF() const
{
return SQFloat(m_Timestamp / 86400000000.0d);
return SQFloat(m_Timestamp / 86400000000.0);
}
/* --------------------------------------------------------------------------------------------
*
*/
void SetDaysF(SQFloat ammount)
void SetDaysF(SQFloat amount)
{
m_Timestamp = Int64(Float64(ammount) * 86400000000LL);
m_Timestamp = int64_t(double(amount) * 86400000000LL);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQInteger GetDaysI() const
SQMOD_NODISCARD SQInteger GetDaysI() const
{
return SQInteger(m_Timestamp / 86400000000LL);
}
@ -298,31 +291,31 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
void SetDaysI(SQInteger ammount)
void SetDaysI(SQInteger amount)
{
m_Timestamp = Int64(Float64(ammount) * 86400000000LL);
m_Timestamp = int64_t(double(amount) * 86400000000LL);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQFloat GetYearsF() const
SQMOD_NODISCARD SQFloat GetYearsF() const
{
return SQFloat(m_Timestamp / 31557600000000.0d);
return SQFloat(m_Timestamp / 31557600000000.0);
}
/* --------------------------------------------------------------------------------------------
*
*/
void SetYearsF(SQFloat ammount)
void SetYearsF(SQFloat amount)
{
m_Timestamp = Int64(Float64(ammount) * 31557600000000LL);
m_Timestamp = int64_t(double(amount) * 31557600000000LL);
}
/* --------------------------------------------------------------------------------------------
*
*/
SQInteger GetYearsI() const
SQMOD_NODISCARD SQInteger GetYearsI() const
{
return SQInteger(m_Timestamp / 31557600000000LL);
}
@ -330,15 +323,15 @@ public:
/* --------------------------------------------------------------------------------------------
*
*/
void SetYearsI(SQInteger ammount)
void SetYearsI(SQInteger amount)
{
m_Timestamp = Int64(Float64(ammount) * 31557600000000LL);
m_Timestamp = int64_t(double(amount) * 31557600000000LL);
}
private:
// --------------------------------------------------------------------------------------------
Int64 m_Timestamp;
int64_t m_Timestamp;
};
} // Namespace:: SqMod