8#ifndef HPP_ALIB_TIME_TIMEPOINTBASE
9#define HPP_ALIB_TIME_TIMEPOINTBASE 1
16#if ALIB_STRINGS && ALIB_ENUMS
26namespace alib {
namespace time {
29# define sc std::chrono::
73template<
typename TClock,
typename TDerived>
81 using TRaw=
typename TTimePoint::rep;
139 :
span( stdLibValue )
342 {
return sc duration_cast<TDuration>( (
span * multiplier) ); }
350 {
return sc duration_cast<TDuration>( (
span * multiplier) ); }
358 {
span= sc duration_cast<TDuration>( (
span * multiplier) );
return *
this; }
366 {
span= sc duration_cast<TDuration>( (
span * multiplier) );
return *
this; }
374 {
return sc duration_cast<TDuration>( (
span / divisor) ); }
382 {
return sc duration_cast<TDuration>( (
span / divisor) ); }
390 {
span= sc duration_cast<TDuration>( (
span / divisor) );
return *
this; }
399 {
span= sc duration_cast<TDuration>( (
span / divisor) );
return *
this; }
413 return double( sc duration_cast<sc microseconds>(
span ).count() )
414 / (1000000. * 3600. * 24. );
423 return integer( sc duration_cast<sc hours>(
span ).count()
433 return double( sc duration_cast<sc microseconds>(
span ).count() )
434 / (1000000. * 3600. );
443 return integer( sc duration_cast<sc hours>(
span ).count() );
452 return double( sc duration_cast<sc microseconds>(
span ).count() )
462 return sc duration_cast<sc minutes>(
span ).count();
471 return double( sc duration_cast<sc nanoseconds>(
span ).count() )
481 return sc duration_cast<sc seconds>(
span ).count();
490 return double( sc duration_cast<sc nanoseconds>(
span ).count() )
500 return sc duration_cast<sc milliseconds>(
span ).count();
509 return double(sc duration_cast<sc nanoseconds>(
span ).count())
519 return sc duration_cast<sc microseconds>(
span ).count();
528 return sc duration_cast<sc nanoseconds>(
span ).count();
539 double InHertz(
int qtyFractionalDigits= -1 )
const
542 if (
span.count() == 0)
549 if ( qtyFractionalDigits < 0 )
553 double mag= pow( 10, qtyFractionalDigits );
554 return static_cast<int>( hz * mag + ( hz < 0 ? -0.5 : 0.5 ) )
566 {
return sc duration_cast<TDuration>(sc hours(24) * days); }
575 {
return sc duration_cast<TDuration>(sc hours(24) * days); }
584 {
return sc duration_cast<TDuration>(sc hours(1) * hours); }
593 {
return sc duration_cast<TDuration>( sc hours(1) * hours ); }
602 {
return sc duration_cast<TDuration>( sc minutes(1) * minutes ); }
611 {
return sc duration_cast<TDuration>( sc minutes(1) * minutes ); }
620 {
return sc duration_cast<TDuration>(sc seconds(1) * seconds ); }
629 {
return sc duration_cast<TDuration>(sc seconds(1) * seconds); }
638 {
return sc duration_cast<TDuration>(sc milliseconds(1) * milliseconds); }
647 {
return sc duration_cast<TDuration>( sc milliseconds(1) * milliseconds ); }
656 {
return sc duration_cast<TDuration>(sc microseconds(1) * microseconds ); }
665 {
return sc duration_cast<TDuration>( sc microseconds(1) * microseconds ); }
674 {
return sc duration_cast<TDuration>(sc nanoseconds( nanoseconds )); }
710 stamp= TClock::now();
718 TDerived
Now() {
return TDerived(TClock::now()); }
730 TDerived
EndOfEpoch() {
return TDerived((TClock::time_point::max)()); }
739 stamp= TClock::now();
740 return *
static_cast<TDerived*
>(
this);
751 :
stamp(internalValue)
814 {
return stamp.time_since_epoch().count(); }
831 {
return TDerived(
TTimePoint(
typename TClock::duration( raw ) ) ); }
839 {
return stamp + sc duration_cast<typename TClock::duration>( timeSpan.
span ); }
847 {
return stamp + timeSpan; }
856 stamp+= sc duration_cast<typename TClock::duration>( timeSpan.
span );
874 {
return stamp - sc duration_cast<typename TClock::duration>( timeSpan.
span ); }
882 {
return stamp - timeSpan; }
936 {
return (*
this) - other; }
947 {
return Age() > timeSpan; }
int64_t InAbsoluteMilliseconds() const
Duration operator/(int64_t divisor) const
static Duration FromNanoseconds(int64_t nanoseconds)
Duration & SetMinimum(const Duration &other)
static Duration FromAbsoluteMicroseconds(int64_t microseconds)
bool operator>(const TDuration &other) const
sc steady_clock::duration TDuration
The value type for time spans.
Duration operator-(const Duration &rhs) const
Duration(const TDuration &stdLibValue)
int64_t InAbsoluteSeconds() const
Duration & SetMaximum(const Duration &other)
static Duration FromMicroseconds(double microseconds)
constexpr Duration()
Creates a zero-length time span.
bool operator<=(const Duration &other) const
Duration operator+(const Duration &rhs) const
Duration operator*(int64_t multiplier) const
Duration & operator*=(double multiplier)
bool operator>=(const TDuration &other) const
Duration & operator+=(const Duration &other)
Duration operator*(double multiplier) const
static Duration FromAbsoluteMilliseconds(int64_t milliseconds)
Duration & operator-=(const TDuration &other)
TDuration span
The internal time value.
static Duration FromHours(double hours)
Duration & operator=(const TDuration &stdLibValue)
integer InAbsoluteHours() const
int64_t InAbsoluteMinutes() const
bool operator<(const TDuration &other) const
bool operator==(const Duration &other) const
static Duration FromMilliseconds(double milliseconds)
bool operator==(const TDuration &other) const
Duration operator/(double divisor) const
bool operator!=(const Duration &other) const
int64_t InNanoseconds() const
Duration operator-(const TDuration &rhs) const
static Duration FromAbsoluteSeconds(int64_t seconds)
static Duration FromAbsoluteHours(int64_t hours)
Duration & operator/=(int64_t divisor)
int64_t InAbsoluteMicroseconds() const
Duration & operator+=(const TDuration &other)
static Duration FromAbsoluteMinutes(int64_t minutes)
Duration & operator/=(double divisor)
static Duration Import(const TDuration &timeSpan)
bool operator!=(const TDuration &other) const
bool operator<(const Duration &other) const
double InHertz(int qtyFractionalDigits=-1) const
Duration & operator*=(int64_t multiplier)
Duration & operator-=(const Duration &other)
bool operator>(const Duration &other) const
Duration operator+(const TDuration &rhs) const
double InMicroseconds() const
static Duration FromSeconds(double seconds)
static Duration FromMinutes(double minutes)
static Duration FromAbsoluteDays(int64_t days)
bool operator<=(const TDuration &other) const
bool operator>=(const Duration &other) const
static Duration FromDays(double days)
integer InAbsoluteDays() const
double InMilliseconds() const
TDerived operator-(const Duration &timeSpan) const
void SetAs(const TDerived &other)
Duration operator-(const TDerived &other) const
TDerived operator-(const typename Duration::TDuration &timeSpan) const
void SetFromRaw(TRaw raw)
bool IsOlderThan(const Duration &timeSpan) const
TDerived operator+(const Duration &timeSpan) const
typename TClock::time_point TTimePoint
The internal c++ type for time points.
Duration Since(const TDerived &other) const
TDerived operator-=(const typename Duration::TDuration &timeSpan)
static TDerived EndOfEpoch()
TDerived operator-=(const Duration &timeSpan)
TDerived operator+=(const Duration &timeSpan)
constexpr TimePointBase(const lang::Initialization init=lang::Initialization::Default)
typename TTimePoint::rep TRaw
Integral type used for exporting and importing values in raw units.
TTimePoint Export() const
void Import(TTimePoint timePoint)
constexpr TimePointBase(TTimePoint internalValue)
static TDerived BeginningOfEpoch()
TDerived operator+(const typename Duration::TDuration &timeSpan) const
static TDerived FromRaw(TRaw raw)
TDerived operator+=(const typename Duration::TDuration &timeSpan)
#define ALIB_ASSERT_MODULE(modulename)
Initialization
Used for example with constructors that allow to suppress initialization of members.
lang::integer integer
Type alias in namespace alib.