2016-03-25 13:28:07 +01:00
|
|
|
#ifndef _LIBRARY_CHRONO_HPP_
|
|
|
|
#define _LIBRARY_CHRONO_HPP_
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include "SqBase.hpp"
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
2016-06-04 18:17:42 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
class Date;
|
|
|
|
class Time;
|
|
|
|
class Datetime;
|
|
|
|
class Timer;
|
|
|
|
class Timestamp;
|
2016-03-25 13:28:07 +01:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
2016-06-04 18:17:42 +02:00
|
|
|
* Class that offers helpers to work with time related information.
|
2016-03-25 13:28:07 +01:00
|
|
|
*/
|
2016-06-04 18:17:42 +02:00
|
|
|
class Chrono
|
|
|
|
{
|
|
|
|
public:
|
2016-03-25 13:28:07 +01:00
|
|
|
|
2016-06-04 18:17:42 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static const Uint8 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 GetCurrentSysTime();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the epoch time as microseconds.
|
|
|
|
*/
|
|
|
|
static Int64 GetEpochTimeMicro();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the epoch time as milliseconds.
|
|
|
|
*/
|
|
|
|
static Int64 GetEpochTimeMilli();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* See whether the specified date is valid.
|
|
|
|
*/
|
|
|
|
static bool ValidDate(Uint16 year, Uint8 month, Uint8 day);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* See whether the specified year is a leap year.
|
|
|
|
*/
|
|
|
|
static bool IsLeapYear(Uint16 year)
|
|
|
|
{
|
|
|
|
return !(year % 400) || (!(year % 4) && (year % 100));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* retrieve the number of days in the specified year.
|
|
|
|
*/
|
|
|
|
static Uint16 DaysInYear(Uint16 year)
|
|
|
|
{
|
|
|
|
return IsLeapYear(year) ? 366 : 365;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the number of days in the specified month.
|
|
|
|
*/
|
|
|
|
static Uint8 DaysInMonth(Uint16 year, Uint8 month);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the number/position of the specified day in the specified year and month.
|
|
|
|
*/
|
|
|
|
static Uint16 DayOfYear(Uint16 year, Uint8 month, Uint8 day);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Convert just the year and day of year to full date.
|
|
|
|
*/
|
|
|
|
static Date ReverseDayOfyear(Uint16 year, Uint16 doy);
|
|
|
|
};
|
2016-03-25 13:28:07 +01:00
|
|
|
|
|
|
|
} // Namespace:: SqMod
|
|
|
|
|
|
|
|
#endif // _LIBRARY_CHRONO_HPP_
|