6#if ORIGINAL_COMPILER_GCC || ORIGINAL_COMPILER_CLANG
8#elif ORIGINAL_COMPILER_MSVC
9#ifndef WIN32_LEAN_AND_MEAN
10#define WIN32_LEAN_AND_MEAN
13#include <sysinfoapi.h>
61 UNIT_FACTOR_BASE * 1000,
62 UNIT_FACTOR_BASE * 1000 * 1000,
63 UNIT_FACTOR_BASE * 1000 * 1000 * 1000,
64 UNIT_FACTOR_BASE * 1000 * 1000 * 1000 * 60,
65 UNIT_FACTOR_BASE * 1000 * 1000 * 1000 * 60 * 60,
66 UNIT_FACTOR_BASE * 1000 * 1000 * 1000 * 60 * 60 * 24,
159#if ORIGINAL_COMPILER_GCC || ORIGINAL_COMPILER_CLANG
168#elif ORIGINAL_COMPILER_MSVC
224#if ORIGINAL_COMPILER_GCC || ORIGINAL_COMPILER_CLANG
233#elif ORIGINAL_COMPILER_MSVC
234 explicit operator DWORD()
const;
414#if ORIGINAL_COMPILER_GCC || ORIGINAL_COMPILER_CLANG
421#elif ORIGINAL_COMPILER_MSVC
458#if ORIGINAL_COMPILER_GCC || ORIGINAL_COMPILER_CLANG
467#elif ORIGINAL_COMPILER_MSVC
468 explicit operator DWORD()
const;
568 enum class calendar :
integer {
577 enum class weekdays :
integer {
588 static constexpr integer DAYS_OF_MONTH[] {
589 31, 28, 31, 30, 31, 30,
590 31, 31, 30, 31, 30, 31
612 static constexpr bool isValidDay(
integer day);
630 static constexpr auto SATURDAY = weekdays::SATURDAY;
632 static constexpr auto SUNDAY = weekdays::SUNDAY;
634 static constexpr auto MONDAY = weekdays::MONDAY;
636 static constexpr auto TUESDAY = weekdays::TUESDAY;
640 static constexpr auto THURSDAY = weekdays::THURSDAY;
642 static constexpr auto FRIDAY = weekdays::FRIDAY;
848 point toPoint()
const;
959 time::UTCTime
operator+(
const time::UTCTime& t,
const time::duration& d);
961 time::UTCTime
operator+(
const time::duration& d,
const time::UTCTime& t);
963 time::UTCTime
operator-(
const time::UTCTime& t,
const time::duration& d);
965 time::duration
operator-(
const time::UTCTime& lhs,
const time::UTCTime& rhs);
977 inline time::duration
operator""_ns(
const unsigned long long val) {
978 return time::duration(
static_cast<time::time_val_type
>(val), time::NANOSECOND);
986 inline time::duration
operator""_us(
const unsigned long long val) {
987 return time::duration(
static_cast<time::time_val_type
>(val), time::MICROSECOND);
995 inline time::duration
operator""_ms(
const unsigned long long val) {
996 return time::duration(
static_cast<time::time_val_type
>(val), time::MILLISECOND);
1004 inline time::duration
operator""_s(
const unsigned long long val) {
1005 return time::duration(
static_cast<time::time_val_type
>(val), time::SECOND);
1013 inline time::duration
operator""_min(
const unsigned long long val) {
1014 return time::duration(
static_cast<time::time_val_type
>(val), time::MINUTE);
1022 inline time::duration
operator""_h(
const unsigned long long val) {
1023 return time::duration(
static_cast<time::time_val_type
>(val), time::HOUR);
1031 inline time::duration
operator""_d(
const unsigned long long val) {
1032 return time::duration(
static_cast<time::time_val_type
>(val), time::DAY);
1040 inline time::duration
operator""_ns(
const long double val) {
1041 return time::duration(std::llround(val * time::FACTOR_NANOSECOND), time::NANOSECOND);
1049 inline time::duration
operator""_us(
const long double val) {
1050 return time::duration(std::llround(val * time::FACTOR_MICROSECOND), time::NANOSECOND);
1058 inline time::duration
operator""_ms(
const long double val) {
1059 return time::duration(std::llround(val * time::FACTOR_MILLISECOND), time::NANOSECOND);
1067 inline time::duration
operator""_s(
const long double val) {
1068 return time::duration(std::llround(val * time::FACTOR_SECOND), time::NANOSECOND);
1076 inline time::duration
operator""_min(
const long double val) {
1077 return time::duration(std::llround(val * time::FACTOR_MINUTE), time::NANOSECOND);
1085 inline time::duration
operator""_h(
const long double val) {
1086 return time::duration(std::llround(val * time::FACTOR_HOUR), time::NANOSECOND);
1094 inline time::duration
operator""_d(
const long double val) {
1095 return time::duration(std::llround(val * time::FACTOR_DAY), time::NANOSECOND);
1124 throw valueError(
"Invalid time unit specified for duration construction");
1128#if ORIGINAL_COMPILER_GCC || ORIGINAL_COMPILER_CLANG
1131#elif ORIGINAL_COMPILER_MSVC
1137 this->operator=(std::move(
other));
1145 this->nano_seconds_ =
other.nano_seconds_;
1146 other.nano_seconds_ = 0;
1176 throw valueError(
"Invalid time unit specified for duration value conversion");
1183 if (this->nano_seconds_ ==
other.nano_seconds_)
1185 return this->nano_seconds_ >
other.nano_seconds_ ? 1 : -1;
1194 return "time::duration";
1198 std::stringstream
ss;
1199 ss <<
"(" << this->className() <<
" " << this->nano_seconds_ <<
"ns)";
1205#if ORIGINAL_COMPILER_GCC || ORIGINAL_COMPILER_CLANG
1206inline original::time::duration::operator
timespec()
const
1211 return timespec{seconds,
static_cast<long>(nanoseconds)};
1214inline timespec original::time::duration::toTimespec()
const
1216 return static_cast<timespec
>(*this);
1218#elif ORIGINAL_COMPILER_MSVC
1219inline original::time::duration::operator DWORD()
const
1221 return static_cast<DWORD
>(this->value());
1224inline DWORD original::time::duration::toDWMilliseconds()
const
1226 return static_cast<DWORD
>(*this);
1232 this->nano_seconds_ += 1;
1239 this->nano_seconds_ += 1;
1245 this->nano_seconds_ -= 1;
1252 this->nano_seconds_ -= 1;
1258 this->nano_seconds_ +=
other.nano_seconds_;
1264 this->nano_seconds_ -=
other.nano_seconds_;
1270 this->nano_seconds_ *=
factor;
1276 this->nano_seconds_ /=
factor;
1282 this->nano_seconds_ /=
other.nano_seconds_;
1334 res.nano_seconds_ = -
res.nano_seconds_;
1387#if ORIGINAL_COMPILER_GCC || (ORIGINAL_COMPILER_CLANG && ORIGINAL_PLATFORM_LINUX)
1391#elif ORIGINAL_PLATFORM_APPLE
1396#elif ORIGINAL_COMPILER_MSVC
1414 : nano_since_epoch_(
val,
unit) {}
1417 : nano_since_epoch_(
std::
move(
d)) {}
1419#if ORIGINAL_COMPILER_GCC || ORIGINAL_COMPILER_CLANG
1421 : nano_since_epoch_(
ts) {}
1422#elif ORIGINAL_COMPILER_MSVC
1424 : nano_since_epoch_(milliseconds) {}
1429 return this->nano_since_epoch_.value(
unit);
1434 return this->nano_since_epoch_.
compareTo(
other.nano_since_epoch_);
1439 return this->nano_since_epoch_.
toHash();
1443 return "time::point";
1448 std::stringstream
ss;
1449 ss <<
"(" << this->className() <<
" " << this->nano_since_epoch_.nano_seconds_ <<
")";
1455#if ORIGINAL_COMPILER_GCC || ORIGINAL_COMPILER_CLANG
1456inline original::time::point::operator
timespec()
const
1458 return static_cast<timespec>(this->nano_since_epoch_);
1461inline timespec original::time::point::toTimespec()
const
1463 return static_cast<timespec>(*this);
1465#elif ORIGINAL_COMPILER_MSVC
1466inline original::time::point::operator DWORD()
const
1468 return static_cast<DWORD
>(this->nano_since_epoch_);
1471inline DWORD original::time::point::toDWMilliseconds()
const
1473 return static_cast<DWORD
>(*this);
1479 ++this->nano_since_epoch_;
1486 ++this->nano_since_epoch_;
1492 --this->nano_since_epoch_;
1499 --this->nano_since_epoch_;
1505 this->nano_since_epoch_ +=
d;
1511 this->nano_since_epoch_ -=
d;
1524 return lhs.nano_since_epoch_ -
rhs.nano_since_epoch_;
1540original::time::UTCTime::isValidYear(
const integer year) {
1545original::time::UTCTime::isValidMonth(
const integer month) {
1546 return 1 <= month && month <= 12;
1550original::time::UTCTime::isValidDay(
const integer day) {
1551 return 1 <= day && day <= 31;
1554inline void original::time::UTCTime::set(
const integer year,
const integer month,
const integer day,
1555 const integer hour,
const integer minute,
const integer second) {
1557 this->month_ = month;
1560 this->minute_ = minute;
1561 this->second_ = second;
1572#if ORIGINAL_COMPILER_GCC || ORIGINAL_COMPILER_CLANG
1575#if ORIGINAL_PLATFORM_WINDOWS
1582#if ORIGINAL_PLATFORM_WINDOWS
1609 if (!isValidYear(
year))
1611 return (
year % 4 == 0 &&
year % 100 != 0) || (
year % 400 == 0);
1616 if (!isValidYear(
year) || !isValidMonth(
month))
1620 return DAYS_OF_MONTH[
month - 1] + 1;
1622 return DAYS_OF_MONTH[
month - 1];
1625constexpr original::time::UTCTime::weekdays
1628 throw valueError(
"Invalid date for weekday calculation: " +
1629 formatString(
year) +
"-" + formatString(
month) +
"-" + formatString(
day));
1642 return static_cast<weekdays
>((
1654 if (!isValidYear(
year) || !isValidMonth(
month) || !isValidDay(
day))
1664 0 <= second && second <= 59;
1674 return isLeapYear(this->year_);
1677inline original::time::UTCTime::weekdays
1679 return weekday(this->year_, this->month_, this->day_);
1691 throw valueError(
"Invalid UTC time parameters: " +
1692 formatString(
year) +
"-" + formatString(
month) +
"-" + formatString(
day) +
" " +
1693 formatString(
hour) +
":" + formatString(
minute) +
":" + formatString(second));
1740 this->operator=(std::move(
other));
1756 return UTCTime{this->year_, this->month_, this->day_};
1763 return this->second_;
1765 return this->minute_;
1771 throw valueError(
"Invalid time unit for UTCTime value access");
1779 return this->month_;
1783 throw valueError(
"Invalid calendar component for UTCTime value access");
1810 return static_cast<point>(*this);
1815 if (this->year_ !=
other.year_)
1816 return this->year_ >
other.year_ ? 1 : -1;
1817 if (this->month_ !=
other.month_)
1818 return this->month_ >
other.month_ ? 1 : -1;
1819 if (this->day_ !=
other.day_)
1820 return this->day_ >
other.day_ ? 1 : -1;
1821 if (this->hour_ !=
other.hour_)
1822 return this->hour_ >
other.hour_ ? 1 : -1;
1823 if (this->minute_ !=
other.minute_)
1824 return this->minute_ >
other.minute_ ? 1 : -1;
1825 if (this->second_ !=
other.second_)
1826 return this->second_ >
other.second_ ? 1 : -1;
1834 this-> hour_, this->minute_, this->second_);
1839 return "time::UTCTime";
1843 std::stringstream
ss;
1844 ss <<
"(" << this->className() <<
" "
1845 << this->year_ <<
"-"
1846 << std::setw(2) << std::setfill(
'0') << this->month_ <<
"-"
1847 << std::setw(2) << std::setfill(
'0') << this->day_ <<
" "
1848 << std::setw(2) << std::setfill(
'0') << this->hour_ <<
":"
1849 << std::setw(2) << std::setfill(
'0') << this->minute_ <<
":"
1850 << std::setw(2) << std::setfill(
'0') << this->second_ <<
")";
integer compareTo(const autoPtr &other) const override
Compare reference counters.
Definition autoPtr.h:714
u_integer toHash() const noexcept override
Compute hash value for the pointer.
Definition autoPtr.h:735
Base class for comparable objects.
Definition comparable.h:35
static u_integer hashFunc(const T &t) noexcept
Default hash function fallback.
static void hashCombine(u_integer &seed, const T &value) noexcept
Combines a hash value with another value's hash.
Definition hash.h:275
Forward declaration of hashable interface template.
Definition hash.h:220
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:37
Base class providing polymorphic string conversion capabilities.
Definition printable.h:39
Abstract base class for unique element containers.
Definition set.h:44
Represents a UTC calendar date and time.
Definition zeit.h:555
static UTCTime localNow()
Returns the current local time as UTCTime.
Definition zeit.h:1603
static constexpr bool isValidYMD(integer year, integer month, integer day)
Checks if year-month-day is valid.
Definition zeit.h:1653
static integer localZonedOffset()
Returns the system's local timezone offset in hours from UTC.
Definition zeit.h:1570
std::string toString(bool enter) const override
Converts UTCTime to string representation (YYYY-MM-DD HH:MM:SS)
Definition zeit.h:1842
static constexpr auto FRIDAY
Constant for Friday.
Definition zeit.h:642
static constexpr bool isValidHMS(integer hour, integer minute, integer second)
Checks if hour-minute-second is valid.
Definition zeit.h:1661
static constexpr auto SATURDAY
Constant for Saturday.
Definition zeit.h:630
static constexpr integer YEARS_CENTURY
Years in a century.
Definition zeit.h:649
static constexpr integer MONTHS_YEAR
Months in a year.
Definition zeit.h:647
friend UTCTime operator+(const UTCTime &t, const duration &d)
Adds duration to UTCTime.
bool isLeapYear() const
Checks if this year is a leap year.
Definition zeit.h:1673
static constexpr integer daysOfMonth(integer year, integer month)
Gets days in specified month.
Definition zeit.h:1615
static constexpr auto MONDAY
Constant for Monday.
Definition zeit.h:634
integer compareTo(const UTCTime &other) const override
Compares this UTCTime to another.
Definition zeit.h:1814
static constexpr auto TUESDAY
Constant for Tuesday.
Definition zeit.h:636
static constexpr integer DAYS_WEEK
Days in a week.
Definition zeit.h:645
static constexpr auto WEDNESDAY
Constant for Wednesday.
Definition zeit.h:638
UTCTime & operator=(const UTCTime &other)=default
Default copy assignment.
static const UTCTime EPOCH
Epoch time constant (1970-01-01 00:00:00)
Definition zeit.h:652
weekdays weekday() const
Gets weekday for this date.
Definition zeit.h:1678
UTCTime(const UTCTime &other)=default
Default copy constructor.
UTCTime date() const
Returns a new UTCTime object containing only the calendar date.
Definition zeit.h:1754
std::string className() const override
Gets the class name.
Definition zeit.h:1838
u_integer toHash() const noexcept override
Computes hash value for this UTCTime.
Definition zeit.h:1831
static constexpr auto THURSDAY
Constant for Thursday.
Definition zeit.h:640
friend UTCTime operator-(const UTCTime &t, const duration &d)
Subtracts duration from UTCTime.
integer value(unit unit) const
Gets time component value.
Definition zeit.h:1760
static constexpr bool isValid(integer year, integer month, integer day, integer hour, integer minute, integer second)
Checks if full date-time is valid.
Definition zeit.h:1668
UTCTime()
Constructs a UTCTime object representing the epoch (1970-01-01 00:00:00 UTC)
Definition zeit.h:1682
static constexpr auto SUNDAY
Constant for Sunday.
Definition zeit.h:632
static UTCTime now()
Gets current UTC time.
Definition zeit.h:1565
Represents a time duration with nanosecond precision.
Definition zeit.h:143
duration & operator*=(time_val_type factor)
Multiplies duration by a factor.
Definition zeit.h:1269
duration(const duration &other)=default
Default copy constructor.
duration & operator+=(const duration &other)
Adds another duration to this one.
Definition zeit.h:1257
u_integer toHash() const noexcept override
Computes hash value for this duration.
Definition zeit.h:1189
friend duration operator/(const duration &lhs, const duration &rhs)
Division operator (duration / duration)
time_val_type value(unit unit=MILLISECOND) const
Gets the duration value in specified units.
Definition zeit.h:1151
std::string className() const override
Gets the class name.
Definition zeit.h:1193
duration(time_val_type val=0, unit unit=MILLISECOND)
Constructs a duration with given value and unit.
Definition zeit.h:1100
floating div(time_val_type factor, unit unit=MILLISECOND) const
Floating-point division by a factor.
Definition zeit.h:1287
duration & operator++()
Prefix increment (adds 1 nanosecond)
Definition zeit.h:1231
std::string toString(bool enter) const override
Converts duration to string representation.
Definition zeit.h:1197
friend duration operator-(const duration &d)
Negation operator.
friend duration operator*(const duration &d, time_val_type factor)
Multiplication operator (duration * factor)
integer compareTo(const duration &other) const override
Compares this duration to another.
Definition zeit.h:1182
static const duration ZERO
Zero duration constant.
Definition zeit.h:150
friend duration operator*(time_val_type factor, const duration &d)
Multiplication operator (factor * duration)
friend duration operator+(const duration &lhs, const duration &rhs)
Addition operator.
friend duration operator/(const duration &d, time_val_type factor)
Division operator (duration / factor)
friend duration abs(const duration &d)
Absolute value of duration.
duration & operator/=(time_val_type factor)
Divides duration by a factor.
Definition zeit.h:1275
duration & operator-=(const duration &other)
Subtracts another duration from this one.
Definition zeit.h:1263
duration & operator--()
Prefix decrement (subtracts 1 nanosecond)
Definition zeit.h:1244
duration & operator=(const duration &other)=default
Default copy assignment.
friend duration operator-(const duration &lhs, const duration &rhs)
Subtraction operator.
Represents a point in time with nanosecond precision.
Definition zeit.h:389
static point now()
Gets current time point.
Definition zeit.h:1386
time_val_type value(unit unit=MILLISECOND) const noexcept
Gets time value in specified units.
Definition zeit.h:1428
std::string className() const override
Gets the class name.
Definition zeit.h:1442
friend point operator-(const point &p, const duration &d)
Subtracts duration from time point.
point & operator--()
Prefix decrement (subtracts 1 nanosecond)
Definition zeit.h:1491
point & operator++()
Prefix increment (adds 1 nanosecond)
Definition zeit.h:1478
point(time_val_type val=0, unit unit=MILLISECOND)
Constructs time point from value and unit.
Definition zeit.h:1413
point & operator-=(const duration &d)
Subtracts duration from time point.
Definition zeit.h:1510
std::string toString(bool enter) const override
Converts time point to string representation.
Definition zeit.h:1447
friend point operator+(const point &p, const duration &d)
Adds duration to time point.
point & operator+=(const duration &d)
Adds duration to time point.
Definition zeit.h:1504
u_integer toHash() const noexcept override
Computes hash value for this time point.
Definition zeit.h:1438
integer compareTo(const point &other) const override
Compares this time point to another.
Definition zeit.h:1433
friend duration operator-(const point &lhs, const point &rhs)
Computes duration between two time points.
Namespace-like class containing time-related utilities.
Definition zeit.h:49
static constexpr time_val_type FACTOR_MILLISECOND
Conversion factor for milliseconds.
Definition zeit.h:104
static constexpr auto NANOSECOND
Constant for nanosecond unit.
Definition zeit.h:85
static constexpr integer EPOCH_DAY
Epoch day (Unix epoch)
Definition zeit.h:124
static constexpr auto DAY
Constant for day unit.
Definition zeit.h:97
static constexpr auto HOUR
Constant for hour unit.
Definition zeit.h:95
static constexpr auto YEAR
Constant for year calendar component.
Definition zeit.h:912
static constexpr integer EPOCH_MONTH
Epoch month (Unix epoch)
Definition zeit.h:122
static constexpr auto MILLISECOND
Constant for millisecond unit.
Definition zeit.h:89
static constexpr auto MINUTE
Constant for minute unit.
Definition zeit.h:93
static constexpr time_val_type FACTOR_NANOSECOND
Conversion factor for nanoseconds.
Definition zeit.h:100
unit
Time units supported by the library.
Definition zeit.h:74
@ MILLISECOND
Milliseconds (1e-3 seconds)
@ MINUTE
Minutes (60 seconds)
@ MICROSECOND
Microseconds (1e-6 seconds)
@ DAY
Days (86400 seconds)
@ HOUR
Hours (3600 seconds)
@ NANOSECOND
Nanoseconds (1e-9 seconds)
static constexpr auto SECOND
Constant for second unit.
Definition zeit.h:91
static constexpr time_val_type FACTOR_DAY
Conversion factor for days.
Definition zeit.h:112
static constexpr integer DAYS_COMMON_YEAR
Days in a common year.
Definition zeit.h:117
static constexpr auto MICROSECOND
Constant for microsecond unit.
Definition zeit.h:87
static constexpr time_val_type FACTOR_MINUTE
Conversion factor for minutes.
Definition zeit.h:108
integer time_val_type
Type used for storing time values.
Definition zeit.h:52
static constexpr integer DAYS_LEAP_YEAR
Days in a leap year.
Definition zeit.h:115
static constexpr time_val_type FACTOR_SECOND
Conversion factor for seconds.
Definition zeit.h:106
static constexpr time_val_type FACTOR_HOUR
Conversion factor for hours.
Definition zeit.h:110
static constexpr integer EPOCH_YEAR
Epoch year (Unix epoch)
Definition zeit.h:120
static constexpr time_val_type FACTOR_MICROSECOND
Conversion factor for microseconds.
Definition zeit.h:102
static constexpr auto MONTH
Constant for month calendar component.
Definition zeit.h:910
Exception for invalid parameter values.
Definition error.h:219
Interface for objects that can be compared.
Platform-independent type definitions and compiler/platform detection.
Custom exception classes and callback validation utilities.
Provides a generic hashing utility and interface for hashable types.
User-defined literals for time durations.
Main namespace for the project Original.
Definition algorithms.h:21
auto operator+(const iterator< T > &it, integer steps) -> iterator< T > *
Adds a number of steps to the iterator's current position and returns a new iterator.
auto operator-(const iterator< T > &it, integer steps) -> iterator< T > *
Subtracts a number of steps from the iterator's current position and returns a new iterator.
TYPE abs(TYPE a)
Returns the absolute value of a given number.
time::duration operator*(const time::duration &d, time::time_val_type factor)
Definition zeit.h:1353
time::duration operator/(const time::duration &d, time::time_val_type factor)
Definition zeit.h:1365
Standard namespace extensions for original::alternative.
Definition allocator.h:351
Interface for polymorphic string formatting and output.