2016-03-25 13:28:07 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include "Library/Chrono/Date.hpp"
|
2016-06-04 21:33:34 +02:00
|
|
|
#include "Library/Chrono/Timestamp.hpp"
|
2021-01-30 07:51:39 +01:00
|
|
|
#include "Core/Utility.hpp"
|
2016-03-25 13:28:07 +01:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
2016-03-26 17:18:41 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
SQMOD_DECL_TYPENAME(Typename, _SC("SqDate"))
|
2016-03-26 17:18:41 +01:00
|
|
|
|
2016-03-25 13:28:07 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-11-15 20:20:33 +01:00
|
|
|
SQChar Date::Delimiter = '-';
|
2016-03-25 13:28:07 +01:00
|
|
|
|
2016-06-04 18:17:42 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t Date::Compare(const Date & o) const
|
2016-06-04 18:17:42 +02:00
|
|
|
{
|
|
|
|
if (m_Year < o.m_Year)
|
2021-01-30 07:51:39 +01:00
|
|
|
{ // NOLINT(bugprone-branch-clone)
|
2016-06-04 18:17:42 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if (m_Year > o.m_Year)
|
2021-01-30 07:51:39 +01:00
|
|
|
{ // NOLINT(bugprone-branch-clone)
|
2016-06-04 18:17:42 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (m_Month < o.m_Month)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if (m_Month > o.m_Month)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (m_Day < o.m_Day)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if (m_Day > o.m_Day)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
// They're equal
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-25 13:28:07 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Date Date::operator + (const Date & o) const
|
|
|
|
{
|
2016-06-04 10:55:06 +02:00
|
|
|
// Add the components individually
|
2016-03-25 13:28:07 +01:00
|
|
|
return Date(o);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Date Date::operator - (const Date & o) const
|
|
|
|
{
|
|
|
|
return Date(o);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Date Date::operator * (const Date & o) const
|
|
|
|
{
|
|
|
|
return Date(o);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Date Date::operator / (const Date & o) const
|
|
|
|
{
|
|
|
|
return Date(o);
|
|
|
|
}
|
|
|
|
|
2016-03-26 17:18:41 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
String Date::ToString() const
|
2016-03-25 13:28:07 +01:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
return fmt::format("{:04}{}{:02}{}{:02}", m_Year, m_Delimiter, m_Month, m_Delimiter, m_Day);
|
2016-03-26 17:18:41 +01:00
|
|
|
}
|
2016-03-25 13:28:07 +01:00
|
|
|
|
2016-03-26 17:18:41 +01:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
void Date::Set(uint16_t year, uint8_t month, uint8_t day)
|
2016-03-26 17:18:41 +01:00
|
|
|
{
|
2016-06-04 18:17:42 +02:00
|
|
|
if (!Chrono::ValidDate(year, month, day))
|
|
|
|
{
|
2021-02-03 16:50:39 +01:00
|
|
|
STHROWF("Invalid date: {:04}{:c}{:02}{:c}{:02}" , m_Year, m_Delimiter, m_Month, m_Delimiter, m_Day);
|
2016-06-04 18:17:42 +02:00
|
|
|
}
|
|
|
|
// Assign the specified values
|
|
|
|
m_Year = year;
|
|
|
|
m_Month = month;
|
|
|
|
m_Day = day;
|
2016-03-26 17:18:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
void Date::SetStr(const SQChar * str)
|
2016-03-26 17:18:41 +01:00
|
|
|
{
|
|
|
|
// The format specifications that will be used to scan the string
|
2016-06-04 18:17:42 +02:00
|
|
|
static SQChar fs[] = _SC(" %u - %u - %u ");
|
2016-03-26 17:18:41 +01:00
|
|
|
// Is the specified string empty?
|
|
|
|
if (!str || *str == '\0')
|
|
|
|
{
|
|
|
|
// Clear the values
|
|
|
|
m_Year = 0;
|
|
|
|
m_Month = 0;
|
|
|
|
m_Day = 0;
|
|
|
|
// We're done here
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Assign the specified delimiter
|
|
|
|
fs[4] = m_Delimiter;
|
|
|
|
fs[9] = m_Delimiter;
|
|
|
|
// The sscanf function requires at least 32 bit integers
|
2021-01-30 07:51:39 +01:00
|
|
|
uint32_t year = 0, month = 0, day = 0;
|
2016-03-26 17:18:41 +01:00
|
|
|
// 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
|
2021-01-30 07:51:39 +01:00
|
|
|
Set(ClampL< uint32_t, uint8_t >(year),
|
|
|
|
ClampL< uint32_t, uint8_t >(month),
|
|
|
|
ClampL< uint32_t, uint8_t >(day)
|
2016-03-26 17:18:41 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
void Date::SetDayOfYear(uint16_t doy)
|
2016-03-26 17:18:41 +01:00
|
|
|
{
|
2016-06-04 10:55:06 +02:00
|
|
|
// Reverse the given day of year to a full date
|
2021-01-30 07:51:39 +01:00
|
|
|
Date d = Chrono::ReverseDayOfYear(m_Year, doy);
|
2016-06-04 10:55:06 +02:00
|
|
|
// Set the obtained month
|
|
|
|
SetMonth(d.m_Month);
|
|
|
|
// Set the obtained day
|
|
|
|
SetDay(d.m_Day);
|
|
|
|
}
|
2016-03-26 17:18:41 +01:00
|
|
|
|
2016-06-04 10:55:06 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
void Date::SetYear(uint16_t year)
|
2016-06-04 10:55:06 +02:00
|
|
|
{
|
|
|
|
// Make sure the year is valid
|
|
|
|
if (!year)
|
|
|
|
{
|
2021-02-03 16:50:39 +01:00
|
|
|
STHROWF("Invalid year: {}", year);
|
2016-06-04 10:55:06 +02:00
|
|
|
}
|
|
|
|
// Assign the value
|
|
|
|
m_Year = year;
|
|
|
|
// Make sure the new date is valid
|
2016-06-04 18:17:42 +02:00
|
|
|
if (!Chrono::ValidDate(m_Year, m_Month, m_Day))
|
2016-06-04 10:55:06 +02:00
|
|
|
{
|
|
|
|
m_Month = 1;
|
|
|
|
m_Day = 1;
|
|
|
|
}
|
2016-03-26 17:18:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
void Date::SetMonth(uint8_t month)
|
2016-03-26 17:18:41 +01:00
|
|
|
{
|
2016-06-04 10:55:06 +02:00
|
|
|
// Make sure the month is valid
|
|
|
|
if (month == 0 || month > 12)
|
|
|
|
{
|
2021-02-03 16:50:39 +01:00
|
|
|
STHROWF("Invalid month: {}", month);
|
2016-06-04 10:55:06 +02:00
|
|
|
}
|
|
|
|
// Assign the value
|
|
|
|
m_Month = month;
|
|
|
|
// Make sure the month days are in range
|
2016-06-04 18:17:42 +02:00
|
|
|
if (m_Day > Chrono::DaysInMonth(m_Year, m_Month))
|
2016-06-04 10:55:06 +02:00
|
|
|
{
|
|
|
|
m_Month = 1; // Fall back to the beginning of the month
|
|
|
|
}
|
2016-03-26 17:18:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
void Date::SetDay(uint8_t day)
|
2016-03-26 17:18:41 +01:00
|
|
|
{
|
2016-06-04 10:55:06 +02:00
|
|
|
// Grab the amount of days in the current month
|
2021-01-30 07:51:39 +01:00
|
|
|
const uint8_t dim = Chrono::DaysInMonth(m_Year, m_Month);
|
2016-06-04 10:55:06 +02:00
|
|
|
// Make sure the day is valid
|
|
|
|
if (day == 0)
|
|
|
|
{
|
2021-02-03 16:50:39 +01:00
|
|
|
STHROWF("Invalid day: {}", day);
|
2016-06-04 10:55:06 +02:00
|
|
|
}
|
|
|
|
else if (day > dim)
|
|
|
|
{
|
2021-02-03 16:50:39 +01:00
|
|
|
STHROWF("Day is out of range: {} > {}", day, dim);
|
2016-06-04 10:55:06 +02:00
|
|
|
}
|
|
|
|
// Assign the value
|
|
|
|
m_Day = day;
|
|
|
|
}
|
2016-03-26 17:18:41 +01:00
|
|
|
|
2016-06-04 10:55:06 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
Date & Date::AddYears(int32_t years)
|
2016-06-04 10:55:06 +02:00
|
|
|
{
|
|
|
|
// Do we have a valid amount of years?
|
|
|
|
if (years)
|
|
|
|
{
|
|
|
|
// Add the specified amount of years
|
2021-01-30 07:51:39 +01:00
|
|
|
SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
|
2016-06-04 10:55:06 +02:00
|
|
|
}
|
2016-06-04 18:17:42 +02:00
|
|
|
// Allow chaining operations
|
|
|
|
return *this;
|
2016-03-26 17:18:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
Date & Date::AddMonths(int32_t months)
|
2016-03-26 17:18:41 +01:00
|
|
|
{
|
2016-06-04 10:55:06 +02:00
|
|
|
// Do we have a valid amount of months?
|
2016-06-04 18:17:42 +02:00
|
|
|
if (months)
|
2016-06-04 10:55:06 +02:00
|
|
|
{
|
2016-06-04 18:17:42 +02:00
|
|
|
// Extract the number of years
|
2021-01-30 07:51:39 +01:00
|
|
|
auto years = static_cast< int32_t >(months / 12);
|
2016-06-04 18:17:42 +02:00
|
|
|
// Extract the number of months
|
2016-06-04 10:55:06 +02:00
|
|
|
months = (months % 12) + m_Month;
|
|
|
|
// Do we have extra months?
|
|
|
|
if (months >= 12)
|
|
|
|
{
|
2016-06-04 18:17:42 +02:00
|
|
|
// Increase the years
|
2016-06-04 10:55:06 +02:00
|
|
|
++years;
|
2016-06-04 18:17:42 +02:00
|
|
|
// Subtract one year from months
|
2016-06-04 10:55:06 +02:00
|
|
|
months %= 12;
|
|
|
|
}
|
|
|
|
else if (months < 0)
|
|
|
|
{
|
2016-06-04 18:17:42 +02:00
|
|
|
// Decrease the years
|
2016-06-04 10:55:06 +02:00
|
|
|
--years;
|
2016-06-04 18:17:42 +02:00
|
|
|
// Add one year to months
|
2016-06-04 10:55:06 +02:00
|
|
|
months = 12 - months;
|
|
|
|
}
|
|
|
|
// Are there any years to add?
|
|
|
|
if (years)
|
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
|
2016-06-04 10:55:06 +02:00
|
|
|
}
|
|
|
|
// Add the months
|
2021-01-30 07:51:39 +01:00
|
|
|
SetMonth(static_cast< uint8_t >(months));
|
2016-06-04 10:55:06 +02:00
|
|
|
}
|
2016-06-04 18:17:42 +02:00
|
|
|
// Allow chaining operations
|
|
|
|
return *this;
|
2016-03-26 17:18:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
Date & Date::AddDays(int32_t days)
|
2016-03-26 17:18:41 +01:00
|
|
|
{
|
2016-06-04 10:55:06 +02:00
|
|
|
// Do we have a valid amount of days?
|
2016-06-04 18:17:42 +02:00
|
|
|
if (days)
|
2016-06-04 10:55:06 +02:00
|
|
|
{
|
2016-06-04 18:17:42 +02:00
|
|
|
// Whether the number of days is positive or negative
|
2021-01-30 07:51:39 +01:00
|
|
|
const int32_t dir = days > 0 ? 1 : -1;
|
2016-06-04 10:55:06 +02:00
|
|
|
// Grab current year
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t year = m_Year;
|
2016-06-04 10:55:06 +02:00
|
|
|
// Calculate the days in the current year
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
|
2016-06-04 10:55:06 +02:00
|
|
|
// Calculate the day of year
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t doy = GetDayOfYear() + days;
|
2016-06-04 10:55:06 +02:00
|
|
|
// Calculate the resulting years
|
|
|
|
while (doy > diy || doy < 0)
|
|
|
|
{
|
|
|
|
doy -= diy * dir;
|
|
|
|
year += dir;
|
2021-01-30 07:51:39 +01:00
|
|
|
diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
|
2016-06-04 10:55:06 +02:00
|
|
|
}
|
|
|
|
// Set the obtained year
|
2021-01-30 07:51:39 +01:00
|
|
|
SetYear(static_cast< uint16_t >(year));
|
2016-06-04 10:55:06 +02:00
|
|
|
// Set the obtained day of year
|
2021-01-30 07:51:39 +01:00
|
|
|
SetDayOfYear(static_cast< uint16_t >(doy));
|
2016-06-04 10:55:06 +02:00
|
|
|
}
|
2016-06-04 18:17:42 +02:00
|
|
|
// Allow chaining operations
|
|
|
|
return *this;
|
2016-03-26 17:18:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
Date Date::AndYears(int32_t years)
|
2016-03-26 17:18:41 +01:00
|
|
|
{
|
2016-06-04 10:55:06 +02:00
|
|
|
// Do we have a valid amount of years?
|
|
|
|
if (!years)
|
|
|
|
{
|
2016-06-04 18:17:42 +02:00
|
|
|
return Date(*this); // Return the date as is
|
2016-06-04 10:55:06 +02:00
|
|
|
}
|
|
|
|
// Replicate the current date
|
|
|
|
Date d(*this);
|
|
|
|
// Add the specified amount of years
|
2021-01-30 07:51:39 +01:00
|
|
|
d.SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
|
2016-06-04 10:55:06 +02:00
|
|
|
// Return the resulted date
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
Date Date::AndMonths(int32_t months)
|
2016-06-04 10:55:06 +02:00
|
|
|
{
|
|
|
|
// Do we have a valid amount of months?
|
|
|
|
if (!months)
|
|
|
|
{
|
2016-06-04 18:17:42 +02:00
|
|
|
return Date(*this); // Return the date as is
|
2016-06-04 10:55:06 +02:00
|
|
|
}
|
2016-06-04 18:17:42 +02:00
|
|
|
// Extract the number of years
|
2021-01-30 07:51:39 +01:00
|
|
|
auto years = static_cast< int32_t >(months / 12);
|
2016-06-04 18:17:42 +02:00
|
|
|
// Extract the number of months
|
2016-06-04 10:55:06 +02:00
|
|
|
months = (months % 12) + m_Month;
|
|
|
|
// Do we have extra months?
|
|
|
|
if (months >= 12)
|
|
|
|
{
|
2016-06-04 18:17:42 +02:00
|
|
|
// Increase the years
|
2016-06-04 10:55:06 +02:00
|
|
|
++years;
|
2016-06-04 18:17:42 +02:00
|
|
|
// Subtract one year from months
|
2016-06-04 10:55:06 +02:00
|
|
|
months %= 12;
|
|
|
|
}
|
|
|
|
else if (months < 0)
|
|
|
|
{
|
2016-06-04 18:17:42 +02:00
|
|
|
// Decrease the years
|
2016-06-04 10:55:06 +02:00
|
|
|
--years;
|
2016-06-04 18:17:42 +02:00
|
|
|
// Add one year to months
|
2016-06-04 10:55:06 +02:00
|
|
|
months = 12 - months;
|
|
|
|
}
|
|
|
|
// Replicate the current date
|
|
|
|
Date d(*this);
|
|
|
|
// Are there any years to add?
|
|
|
|
if (years)
|
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
d.SetYear(ConvTo< uint16_t >::From(static_cast< int32_t >(m_Year) + years));
|
2016-06-04 10:55:06 +02:00
|
|
|
}
|
|
|
|
// Add the months
|
2021-01-30 07:51:39 +01:00
|
|
|
d.SetMonth(static_cast< uint8_t >(months));
|
2016-06-04 10:55:06 +02:00
|
|
|
// Return the resulted date
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2021-01-30 07:51:39 +01:00
|
|
|
Date Date::AndDays(int32_t days)
|
2016-06-04 10:55:06 +02:00
|
|
|
{
|
|
|
|
// Do we have a valid amount of days?
|
|
|
|
if (!days)
|
|
|
|
{
|
2016-06-04 18:17:42 +02:00
|
|
|
return Date(*this); // Return the date as is
|
2016-06-04 10:55:06 +02:00
|
|
|
}
|
2016-06-04 18:17:42 +02:00
|
|
|
// Whether the number of days is positive or negative
|
2021-01-30 07:51:39 +01:00
|
|
|
const int32_t dir = days > 0 ? 1 : -1;
|
2016-06-04 10:55:06 +02:00
|
|
|
// Grab current year
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t year = m_Year;
|
2016-06-04 10:55:06 +02:00
|
|
|
// Calculate the days in the current year
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
|
2016-06-04 10:55:06 +02:00
|
|
|
// Calculate the day of year
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t doy = GetDayOfYear() + days;
|
2016-06-04 10:55:06 +02:00
|
|
|
// Calculate the resulting years
|
|
|
|
while (doy > diy || doy < 0)
|
|
|
|
{
|
|
|
|
doy -= diy * dir;
|
|
|
|
year += dir;
|
2021-01-30 07:51:39 +01:00
|
|
|
diy = Chrono::DaysInYear(static_cast< uint16_t >(year));
|
2016-06-04 10:55:06 +02:00
|
|
|
}
|
|
|
|
// Replicate the current date
|
|
|
|
Date d(*this);
|
|
|
|
// Set the obtained year
|
2021-01-30 07:51:39 +01:00
|
|
|
d.SetYear(static_cast< uint16_t >(year));
|
2016-06-04 10:55:06 +02:00
|
|
|
// Set the obtained day of year
|
2021-01-30 07:51:39 +01:00
|
|
|
d.SetDayOfYear(static_cast< uint16_t >(doy));
|
2016-06-04 10:55:06 +02:00
|
|
|
// Return the resulted date
|
|
|
|
return d;
|
2016-03-26 17:18:41 +01:00
|
|
|
}
|
|
|
|
|
2016-06-04 21:33:34 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Timestamp Date::GetTimestamp() const
|
|
|
|
{
|
|
|
|
// Calculate the current day of the year
|
2021-01-30 07:51:39 +01:00
|
|
|
int32_t days = Chrono::DayOfYear(m_Year, m_Month, m_Day);
|
2016-06-04 21:33:34 +02:00
|
|
|
// Calculate all days till the current year
|
2021-01-30 07:51:39 +01:00
|
|
|
for (int32_t year = 0; year < m_Year; --year)
|
2016-06-04 21:33:34 +02:00
|
|
|
{
|
2021-01-30 07:51:39 +01:00
|
|
|
days += Chrono::DaysInYear(static_cast< uint16_t >(year));
|
2016-06-04 21:33:34 +02:00
|
|
|
}
|
|
|
|
// Return the resulted timestamp
|
2021-01-30 07:51:39 +01:00
|
|
|
return Timestamp(static_cast< int64_t >(days * 86400000000LL));
|
2016-06-04 21:33:34 +02:00
|
|
|
}
|
|
|
|
|
2016-03-26 17:18:41 +01:00
|
|
|
// ================================================================================================
|
|
|
|
void Register_ChronoDate(HSQUIRRELVM vm, Table & /*cns*/)
|
|
|
|
{
|
2016-11-15 20:55:03 +01:00
|
|
|
RootTable(vm).Bind(Typename::Str,
|
|
|
|
Class< Date >(vm, Typename::Str)
|
2016-03-26 17:18:41 +01:00
|
|
|
// Constructors
|
|
|
|
.Ctor()
|
2021-01-30 07:51:39 +01:00
|
|
|
.Ctor< uint16_t >()
|
|
|
|
.Ctor< uint16_t, uint8_t >()
|
|
|
|
.Ctor< uint16_t, uint8_t, uint8_t >()
|
2016-03-26 17:18:41 +01:00
|
|
|
// Static Properties
|
|
|
|
.SetStaticValue(_SC("GlobalDelimiter"), &Date::Delimiter)
|
2016-06-03 20:26:19 +02:00
|
|
|
// Core Meta-methods
|
2016-11-15 20:20:33 +01:00
|
|
|
.SquirrelFunc(_SC("_typename"), &Typename::Fn)
|
2016-03-26 17:18:41 +01:00
|
|
|
.Func(_SC("_tostring"), &Date::ToString)
|
2016-11-15 20:48:23 +01:00
|
|
|
.Func(_SC("cmp"), &Date::Cmp)
|
2016-06-03 20:26:19 +02:00
|
|
|
// Meta-methods
|
2016-03-26 17:18:41 +01:00
|
|
|
.Func< Date (Date::*)(const Date &) const >(_SC("_add"), &Date::operator +)
|
|
|
|
.Func< Date (Date::*)(const Date &) const >(_SC("_sub"), &Date::operator -)
|
|
|
|
.Func< Date (Date::*)(const Date &) const >(_SC("_mul"), &Date::operator *)
|
|
|
|
.Func< Date (Date::*)(const Date &) const >(_SC("_div"), &Date::operator /)
|
|
|
|
// Properties
|
2016-06-04 10:55:06 +02:00
|
|
|
.Prop(_SC("Delimiter"), &Date::GetDelimiter, &Date::SetDelimiter)
|
|
|
|
.Prop(_SC("Str"), &Date::GetStr, &Date::SetStr)
|
2016-06-04 18:17:42 +02:00
|
|
|
.Prop(_SC("DayOfYear"), &Date::GetDayOfYear, &Date::SetDayOfYear)
|
2016-03-26 17:18:41 +01:00
|
|
|
.Prop(_SC("Year"), &Date::GetYear, &Date::SetYear)
|
|
|
|
.Prop(_SC("Month"), &Date::GetMonth, &Date::SetMonth)
|
|
|
|
.Prop(_SC("Day"), &Date::GetDay, &Date::SetDay)
|
|
|
|
.Prop(_SC("LeapYear"), &Date::IsThisLeapYear)
|
|
|
|
.Prop(_SC("YearDays"), &Date::GetYearDays)
|
|
|
|
.Prop(_SC("MonthDays"), &Date::GetMonthDays)
|
2016-06-04 21:33:34 +02:00
|
|
|
.Prop(_SC("Timestamp"), &Date::GetTimestamp)
|
2016-03-26 17:18:41 +01:00
|
|
|
// Member Methods
|
|
|
|
.Func(_SC("AddYears"), &Date::AddYears)
|
|
|
|
.Func(_SC("AddMonths"), &Date::AddMonths)
|
|
|
|
.Func(_SC("AddDays"), &Date::AddDays)
|
2016-06-04 10:55:06 +02:00
|
|
|
.Func(_SC("AndYears"), &Date::AndYears)
|
|
|
|
.Func(_SC("AndMonths"), &Date::AndMonths)
|
|
|
|
.Func(_SC("AndDays"), &Date::AndDays)
|
2016-03-26 17:18:41 +01:00
|
|
|
// Overloaded Methods
|
2021-01-30 07:51:39 +01:00
|
|
|
.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)
|
2016-03-26 17:18:41 +01:00
|
|
|
);
|
2016-03-25 13:28:07 +01:00
|
|
|
}
|
|
|
|
|
2016-03-26 17:18:41 +01:00
|
|
|
} // Namespace:: SqMod
|