11#ifndef CCGL_UTILS_TIME_H
12#define CCGL_UTILS_TIME_H
31inline bool IsLeapYear(
const int yr) {
return !(yr % 4) && (yr % 100 || !(yr % 400)); }
69time_t
ConvertToTime(
const string& str_date,
string const& format,
bool include_hour,
bool utc_time =
true);
115int GetYear(time_t date,
bool utc_time =
true);
127int GetDay(time_t date,
bool utc_time =
true);
183 int iminute = 0,
int isecond = 0,
int imillisecond = 0);
202 bool operator<(
const DateTime& value)
const {
return filetime < value.filetime; }
203 bool operator<=(
const DateTime& value)
const {
return filetime <= value.filetime; }
204 bool operator>(
const DateTime& value)
const {
return filetime > value.filetime; }
205 bool operator>=(
const DateTime& value)
const {
return filetime >= value.filetime; }
time_t ConvertYMDToTime(int &year, int &month, int &day, bool utc_time=true)
Convert integer year, month, and day to date time.
int GetDateInfoFromTimet(time_t t, int *year, int *month, int *day, bool utc_time=true)
Get date information from time_t variable.
bool IsLeapYear(const int yr)
Check the given year is a leap year or not.
Definition: utils_time.h:31
void UTCTime(time_t date, struct tm *t)
Get UTC:+00:00 time.
int JulianDay(time_t date, bool utc_time=true)
Get the Julian day from time_t date.
string ConvertToString(const time_t date, bool utc_time=true)
Convert date time to string as the format of "YYYY-MM-DD".
double TimeCounting()
Precisely and cross-platform time counting function.
void GetDateTime(time_t date, struct tm *t, bool utc_time=true)
Get UTC:+00:00 time.
time_t ConvertToTime(const string &str_date, string const &format, bool include_hour, bool utc_time=true)
Convert string to date time, string format could be %4d%2d%2d or d-d-d.
int DayOfYear(time_t date, bool utc_time=true)
Get the day of one year, [1, 366].
int GetMonth(time_t date, bool utc_time=true)
Get the month.
string ConvertToString3(const time_t date, bool utc_time=true)
Convert date time to string as the format of "YYYY_MM_DD_HHMMSS".
int GetYear(time_t date, bool utc_time=true)
Get the year.
string ConvertToString2(const time_t date, bool utc_time=true)
Convert date time to string as the format of "YYYY-MM-DD HH".
int GetDay(time_t date, bool utc_time=true)
Get the day.
void LocalTime(time_t date, struct tm *t)
Get local time.
Common Cross-platform Geographic Library (CCGL)
A type representing the combination of date and time.
Definition: utils_time.h:156
DateTime Backward(int imilliseconds)
Move backward by the delta in milliseconds.
int day_of_week
Day of the week since Sunday - [0, 6].
Definition: utils_time.h:160
int month
Month since January - [1, 12].
Definition: utils_time.h:158
int minute
Minutes after the hour - [0, 59].
Definition: utils_time.h:163
static DateTime UTCTime()
Get the current UTC time.
static DateTime FromDateTime(int iyear, int imonth, int iday, int ihour=0, int iminute=0, int isecond=0, int imillisecond=0)
Create a date time value from each time element value.
int day
Day of the month - [1, 31].
Definition: utils_time.h:159
int day_of_year
Day of the year - [0, 365].
Definition: utils_time.h:161
int second
Seconds after the minute - [0, 59].
Definition: utils_time.h:164
DateTime ToLocalTime()
Convert the UTC time to the local time.
int hour
Hour of the day since midnight - [0, 23].
Definition: utils_time.h:162
int year
Year.
Definition: utils_time.h:157
static DateTime FromFileTime(vuint64_t ifiletime)
Create a date time value from FILETIME.
static DateTime LocalTime()
Get the current local time.
DateTime Forward(int imilliseconds)
Move forward by the delta in milliseconds.
DateTime()
Create an empty date time value.
DateTime ToUTCTime()
Convert the local time to the UTC time.
vuint64_t filetime
The number of 100-nanosecond intervals since January 1, 1601 (UTC).
Definition: utils_time.h:167
int milliseconds
Milliseconds after the second - [0, 999].
Definition: utils_time.h:165
vuint64_t total_milliseconds
Total milliseconds of the time.
Definition: utils_time.h:166