mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
4a6bfc086c
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.
114 lines
4.2 KiB
C++
114 lines
4.2 KiB
C++
#pragma once
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
#include "Core/Common.hpp"
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
namespace SqMod {
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
class Date;
|
|
class Time;
|
|
class Datetime;
|
|
class Timer;
|
|
class Timestamp;
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* Class that offers helpers to work with time related information.
|
|
*/
|
|
class Chrono
|
|
{
|
|
public:
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
static const uint8_t MonthLengths[12];
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Default constructor. (disabled)
|
|
*/
|
|
Chrono() = delete;
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Copy constructor. (disabled)
|
|
*/
|
|
Chrono(const Chrono & o) = delete;
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Move constructor. (disabled)
|
|
*/
|
|
Chrono(Chrono && o) = delete;
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Destructor. (disabled)
|
|
*/
|
|
~Chrono() = delete;
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Copy assignment operator. (disabled)
|
|
*/
|
|
Chrono & operator = (const Chrono & o) = delete;
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Move assignment operator. (disabled)
|
|
*/
|
|
Chrono & operator = (Chrono && o) = delete;
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Retrieve the current time as microseconds.
|
|
*/
|
|
static int64_t GetCurrentSysTime();
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Retrieve the epoch time as microseconds.
|
|
*/
|
|
static int64_t GetEpochTimeMicro();
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Retrieve the epoch time as milliseconds.
|
|
*/
|
|
static int64_t GetEpochTimeMilli();
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* See whether the specified date is valid.
|
|
*/
|
|
static bool ValidDate(uint16_t year, uint8_t month, uint8_t day);
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* See whether the specified year is a leap year.
|
|
*/
|
|
static bool IsLeapYear(uint16_t year)
|
|
{
|
|
return !(year % 400) || (!(year % 4) && (year % 100));
|
|
}
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* retrieve the number of days in the specified year.
|
|
*/
|
|
static uint16_t DaysInYear(uint16_t year)
|
|
{
|
|
return IsLeapYear(year) ? 366 : 365;
|
|
}
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Retrieve the number of days in the specified month.
|
|
*/
|
|
static uint8_t DaysInMonth(uint16_t year, uint8_t month);
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Retrieve the number/position of the specified day in the specified year and month.
|
|
*/
|
|
static uint16_t DayOfYear(uint16_t year, uint8_t month, uint8_t day);
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Convert just the year and day of year to full date.
|
|
*/
|
|
static Date ReverseDayOfYear(uint16_t year, uint16_t doy);
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
* Calculate the number of days in the specified date range.
|
|
*/
|
|
static int64_t DateRangeToSeconds(uint16_t _year, uint8_t _month, uint8_t _day, uint16_t year_, uint8_t month_, uint8_t day_);
|
|
};
|
|
|
|
} // Namespace:: SqMod
|