22 time_t seconds = timestamp.
seconds();
23 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
24 if (gmtime_r(&seconds, &result) != &result)
26 #elif defined(_WIN32) || defined(_WIN64)
27 if (gmtime_s(&result, &seconds))
30 _year = result.tm_year + 1900;
31 _month = result.tm_mon + 1;
33 _day = result.tm_mday;
34 _hour = result.tm_hour;
42 Time::Time(
int year,
int month,
int day,
int hour,
int minute,
int second,
int millisecond,
int microsecond,
int nanosecond)
46 #pragma warning(disable: 4127)
48 if (
sizeof(time_t) == 4)
50 assert(((
year >= 1970) && (
year <= 2038)) &&
"Year value is limited in range from 1970 to 2038!");
56 assert(((
year >= 1970) && (
year <= 3000)) &&
"Year value is limited in range from 1970 to 3000!");
63 assert(((
month >= 1) && (
month <= 12)) &&
"Month value is limited in range from 1 to 12!");
66 assert(((
day >= 1) && (
day <= 31)) &&
"Day value is limited in range from 1 to 31!");
67 if ((
day < 1) || (
day > 31))
69 assert(((
hour >= 0) && (
hour <= 23)) &&
"Hour value is limited in range from 0 to 23!");
72 assert(((
minute >= 0) && (
minute <= 59)) &&
"Minute value is limited in range from 0 to 59!");
75 assert(((
second >= 0) && (
second <= 59)) &&
"Second value is limited in range from 0 to 59!");
78 assert(((
millisecond >= 0) && (
millisecond <= 999)) &&
"Millisecond value is limited in range from 0 to 999!");
81 assert(((
microsecond >= 0) && (
microsecond <= 999)) &&
"Microsecond value is limited in range from 0 to 999!");
84 assert(((
nanosecond >= 0) && (
nanosecond <= 999)) &&
"Nanosecond value is limited in range from 0 to 999!");
103 result.tm_year =
_year - 1900;
104 result.tm_mon =
_month - 1;
105 result.tm_mday =
_day;
106 result.tm_hour =
_hour;
109 result.tm_isdst = -1;
111 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
112 time_t seconds = timegm(&result);
113 #elif defined(_WIN32) || defined(_WIN64)
114 time_t seconds = _mkgmtime(&result);
125 result.tm_year =
_year - 1900;
126 result.tm_mon =
_month - 1;
127 result.tm_mday =
_day;
128 result.tm_hour =
_hour;
131 result.tm_isdst = -1;
133 time_t seconds = mktime(&result);
143 time_t seconds = timestamp.
seconds();
144 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
145 if (gmtime_r(&seconds, &result) != &result)
147 #elif defined(_WIN32) || defined(_WIN64)
148 if (gmtime_s(&result, &seconds))
151 _year = result.tm_year + 1900;
152 _month = result.tm_mon + 1;
154 _day = result.tm_mday;
155 _hour = result.tm_hour;
166 time_t seconds = timestamp.
seconds();
167 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
168 if (localtime_r(&seconds, &result) != &result)
170 #elif defined(_WIN32) || defined(_WIN64)
171 if (localtime_s(&result, &seconds))
174 _year = result.tm_year + 1900;
175 _month = result.tm_mon + 1;
177 _day = result.tm_mday;
178 _hour = result.tm_hour;
LocalTime()
Initialize local time with a current value.
Time() noexcept
Initialize time with an epoch time.
int month() const noexcept
Get month value (1-12)
LocalTimestamp localstamp() const
Get local timestamp from the current date & time value.
int year() const noexcept
Get year value (1970-2038 for 32-bit or 1970-3000 for 64-bit)
int millisecond() const noexcept
Get millisecond value (0-999)
int day() const noexcept
Get day value (1-31)
int minute() const noexcept
Get minute value (0-59)
int second() const noexcept
Get second value (0-59)
int hour() const noexcept
Get hour value (0-23)
int _weekday
Weekday value.
int _millisecond
Millisecond value.
UtcTimestamp utcstamp() const
Get UTC timestamp from the current date & time value.
int microsecond() const noexcept
Get microsecond value (0-999)
int _nanosecond
Nanosecond value.
int nanosecond() const noexcept
Get nanosecond value (0-999)
int _microsecond
Microsecond value.
uint64_t milliseconds() const noexcept
Get total milliseconds of the current timestamp.
uint64_t microseconds() const noexcept
Get total microseconds of the current timestamp.
uint64_t seconds() const noexcept
Get total seconds of the current timestamp.
uint64_t total() const noexcept
Get total value of the current timestamp (total nanoseconds)
uint64_t nanoseconds() const noexcept
Get total nanoseconds of the current timestamp.
UtcTime()
Initialize UTC time with a current value.
#define throwex
Throw extended exception macro.
C++ Common project definitions.
std::string format(fmt::format_string< T... > pattern, T &&... args)
Format string.