4#include "../Common/CompilerMacrosExport.h"
5#include "../Common/PlatformMacrosType.h"
6#ifndef SC_EXPORT_LIBRARY_TIME
7#define SC_EXPORT_LIBRARY_TIME 0
9#define SC_TIME_EXPORT SC_COMPILER_LIBRARY_EXPORT(SC_EXPORT_LIBRARY_TIME)
11#include "../Common/PrimitiveDefinitions.h"
40 constexpr explicit Nanoseconds(int64_t ns) : ns(ns) {};
43 [[nodiscard]]
bool operator>(
const Nanoseconds other)
const {
return ns > other.ns; }
44 [[nodiscard]]
bool operator<(
const Nanoseconds other)
const {
return ns < other.ns; }
45 [[nodiscard]]
bool operator==(
const Nanoseconds other)
const {
return ns == other.ns; }
55 [[nodiscard]]
operator TimeMs()
const {
return {ms}; }
56 [[nodiscard]]
bool operator>(
const Milliseconds other)
const {
return ms > other.ms; }
57 [[nodiscard]]
bool operator<(
const Milliseconds other)
const {
return ms < other.ms; }
58 [[nodiscard]]
bool operator==(
const Milliseconds other)
const {
return ms == other.ms; }
65 constexpr explicit Seconds(int64_t sec) : sec(sec) {};
68 [[nodiscard]]
bool operator>(
const Seconds other)
const {
return sec > other.sec; }
69 [[nodiscard]]
bool operator<(
const Seconds other)
const {
return sec < other.sec; }
70 [[nodiscard]]
bool operator==(
const Seconds other)
const {
return sec == other.sec; }
92 [[nodiscard]]
bool operator>(
const Relative other)
const {
return seconds > other.seconds; }
93 [[nodiscard]]
bool operator<(
const Relative other)
const {
return seconds < other.seconds; }
94 [[nodiscard]]
bool operator==(
const Relative other)
const {
return toNanoseconds() == other.toNanoseconds(); }
96 Seconds toSeconds()
const {
return Seconds(
static_cast<int64_t
>(seconds + 0.5)); }
97 Nanoseconds toNanoseconds()
const {
return Nanoseconds(
static_cast<int64_t
>(seconds * 1e9 + 0.5)); }
98 Milliseconds toMilliseconds()
const {
return Milliseconds(
static_cast<int64_t
>(seconds * 1e3 + 0.5)); }
101 Relative(
double seconds) : seconds(seconds) {}
108inline Time::Nanoseconds
operator""_ns(
unsigned long long int ns) {
return Time::Nanoseconds(
static_cast<int64_t
>(ns)); }
109inline Time::Milliseconds
operator""_ms(
unsigned long long int ms) {
return Time::Milliseconds(
static_cast<int64_t
>(ms)); }
110inline Time::Seconds
operator""_sec(
unsigned long long int sec) {
return Time::Seconds(
static_cast<int64_t
>(sec)); }
127 Absolute(int64_t milliseconds) : TimeMs{milliseconds} {}
129 Absolute(TimeMs time) : TimeMs{time} {}
136 uint8_t dayOfMonth = 0;
137 uint8_t dayOfWeek = 0;
138 uint8_t dayOfYear = 0;
143 const char* getMonth()
const;
144 const char* getDay()
const;
145 bool isDaylightSaving =
false;
148 friend struct Internal;
Holds information on a parsed absolute time from Absolute::parseLocal.
Definition Time.h:133
Absolute time as realtime or monotonically increasing clock.
Definition Time.h:117
Absolute offsetBy(Milliseconds other) const
Offset this absolute time with a relative time in milliseconds.
bool isLaterThanOrEqualTo(Absolute other) const
Check if this Absolute time is later or equal to another Absolute time.
bool isLaterThan(Absolute other) const
Check if this Absolute time is lather than another Absolute time.
Absolute(int64_t milliseconds)
Construct an Absolute from milliseconds since epoch.
Definition Time.h:127
bool parseUTC(ParseResult &result) const
Parses UTC time to a Parsed structure.
Absolute()=default
Construct an Absolute time equal to epoch.
Milliseconds subtractExact(Absolute other) const
Obtains the difference between this time and the other time.
bool parseLocal(ParseResult &result) const
Parses local time to a Parsed structure.
An high resolution time counter.
Definition Time.h:208
Milliseconds toMilliseconds() const
Converts to Milliseconds.
Relative subtractApproximate(HighResolutionCounter other) const
Subtracts another HighResolutionCounter from this one, returning an approximate Relative.
Relative getRelative() const
Converts to a Relative struct.
Nanoseconds toNanoseconds() const
Converts to Nanoseconds.
HighResolutionCounter offsetBy(Milliseconds ms) const
Returns a HighResolutionCounter offset by a given number of Milliseconds.
Seconds toSeconds() const
Converts to Seconds.
bool isLaterThanOrEqualTo(HighResolutionCounter other) const
Check if this HighResolutionCounter is later or equal to another HighResolutionCounter.
HighResolutionCounter & snap()
Sets HighResolutionCounter to current instant Example:
HighResolutionCounter subtractExact(HighResolutionCounter other) const
Subtracts another HighResolutionCounter from this one, returning a precise HighResolutionCounter.
Type-safe wrapper of uint64 used to represent milliseconds.
Definition Time.h:50
Represent monotonically increasing time (use Monotonic::now for current time)
Definition Time.h:184
int64_t getMonotonicMilliseconds() const
Return given time as monotonically incrementing milliseconds.
Definition Time.h:191
static Monotonic now()
Obtain time according to monotonic clock.
Type-safe wrapper of uint64 used to represent nanoseconds.
Definition Time.h:38
Represents a realtime clock in milliseconds since epoch (use Realtime::now for current time)
Definition Time.h:196
static Realtime now()
Obtain time according to realtime clock.
int64_t getMillisecondsSinceEpoch() const
Return given time as milliseconds since epoch.
Definition Time.h:203
Interval of time represented with 64 bit double precision float.
Definition Time.h:77
Relative(Milliseconds time)
Construct a Relative from milliseconds.
Definition Time.h:82
Relative(Seconds time)
Construct a Relative from seconds.
Definition Time.h:88
Relative()
how many seconds have elapsed in
Definition Time.h:79
Relative(Nanoseconds time)
Construct a Relative from nanoseconds.
Definition Time.h:85
Type-safe wrapper of uint64 used to represent seconds.
Definition Time.h:63