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);
79time_t
ConvertYMDToTime(
int& year,
int& month,
int& day,
bool utc_time =
true);
101void UTCTime(time_t date,
struct tm* t);
109void GetDateTime(time_t date,
struct tm* t,
bool utc_time =
true);
115int GetYear(time_t date,
bool utc_time =
true);
121int GetMonth(time_t date,
bool utc_time =
true);
127int GetDay(time_t date,
bool utc_time =
true);
132int DayOfYear(time_t date,
bool utc_time =
true);
137int DayOfYear(
int year,
int month,
int day);
142int JulianDay(time_t date,
bool utc_time =
true);
149int JulianDay(
int year,
int month,
int day);
183 int iminute = 0,
int isecond = 0,
int imillisecond = 0);
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, const bool utc_time)
Convert integer year, month, and day to date time.
Definition: utils_time.cpp:157
int GetDateInfoFromTimet(const time_t t, int *year, int *month, int *day, const bool utc_time)
Get date information from time_t variable.
Definition: utils_time.cpp:182
bool IsLeapYear(const int yr)
Check the given year is a leap year or not.
Definition: utils_time.h:31
void UTCTime(const time_t date, struct tm *t)
Get UTC:+00:00 time.
Definition: utils_time.cpp:205
int JulianDay(const time_t date, const bool utc_time)
Get the Julian day from time_t date.
Definition: utils_time.cpp:257
string ConvertToString(const time_t date, const bool utc_time)
Convert date time to string as the format of "YYYY-MM-DD".
Definition: utils_time.cpp:30
double TimeCounting()
Precisely and cross-platform time counting function.
Definition: utils_time.cpp:13
void GetDateTime(const time_t date, struct tm *t, const bool utc_time)
Get UTC:+00:00 time.
Definition: utils_time.cpp:213
string ConvertToString3(const time_t date, const bool utc_time)
format: 2022_11_17_092000
Definition: utils_time.cpp:76
int DayOfYear(const time_t date, const bool utc_time)
Get the day of one year, [1, 366].
Definition: utils_time.cpp:245
int GetMonth(const time_t date, const bool utc_time)
Get the month.
Definition: utils_time.cpp:229
int GetYear(const time_t date, const bool utc_time)
Get the year.
Definition: utils_time.cpp:221
string ConvertToString2(const time_t date, const bool utc_time)
Convert date time to string as the format of "YYYY-MM-DD HH".
Definition: utils_time.cpp:42
int GetDay(const time_t date, const bool utc_time)
Get the day.
Definition: utils_time.cpp:237
void LocalTime(time_t date, struct tm *t)
Get local time.
Definition: utils_time.cpp:197
time_t ConvertToTime(const string &str_date, string const &format, const bool include_hour, const bool utc_time)
Convert string to date time, string format could be %4d%2d%2d or d-d-d.
Definition: utils_time.cpp:113
Common Cross-platform Geographic Library (CCGL)
Definition: basic.cpp:17
A type representing the combination of date and time.
Definition: utils_time.h:156
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.
Definition: utils_time.cpp:379
DateTime Backward(int imilliseconds)
Move backward by the delta in milliseconds.
Definition: utils_time.cpp:496
static DateTime UTCTime()
Get the current UTC time.
Definition: utils_time.cpp:360
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 FromFileTime(vuint64_t ifiletime)
Create a date time value from FILETIME.
Definition: utils_time.cpp:413
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.
Definition: utils_time.cpp:445
int hour
Hour of the day since midnight - [0, 23].
Definition: utils_time.h:162
int year
Year.
Definition: utils_time.h:157
DateTime Forward(int imilliseconds)
Move forward by the delta in milliseconds.
Definition: utils_time.cpp:488
DateTime()
Create an empty date time value.
Definition: utils_time.cpp:438
static DateTime LocalTime()
Get the current local time.
Definition: utils_time.cpp:341
DateTime ToUTCTime()
Convert the local time to the UTC time.
Definition: utils_time.cpp:467
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