8#ifndef HPP_ALIB_TIME_TIMEPOINTBASE
9#define HPP_ALIB_TIME_TIMEPOINTBASE 1
11#if !defined(HPP_ALIB) && !defined(ALIB_DOX)
17#if ALIB_STRINGS && ALIB_ENUMS
18# if !defined(HPP_ALIB_LANG_COMMONENUMS)
22# if !defined(HPP_ALIB_LANG_COMMONENUMS_DEFS)
27#if !defined(HPP_ALIB_LANG_INTEGERS)
32#if !defined (_GLIBCXX_CHRONO) && !defined (_CHRONO_)
36#if !defined (_GLIBCXX_CMATH) && !defined (_CMATH_)
40#if !defined (_GLIBCXX_ALGORITHM) && !defined(_ALGORITHM_)
44namespace alib {
namespace time {
87template<
typename TClock,
typename TDerived>
95 using TRaw=
typename TTimePoint::rep;
113 #if !defined(ALIB_DOX)
121 using TDuration =
typename std::chrono::steady_clock::duration;
138 :
span( internalValue )
273 return std::chrono::duration_cast<TDuration>( (
span * multiplier) );
283 return std::chrono::duration_cast<TDuration>( (
span * multiplier) );
293 span= std::chrono::duration_cast<TDuration>( (
span * multiplier) );
304 span= std::chrono::duration_cast<TDuration>( (
span * multiplier) );
315 return std::chrono::duration_cast<TDuration>( (
span / divisor) );
325 return std::chrono::duration_cast<TDuration>( (
span / divisor) );
335 span= std::chrono::duration_cast<TDuration>( (
span / divisor) );
347 span= std::chrono::duration_cast<TDuration>( (
span / divisor) );
363 return static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(
span ).count() )
364 / (1000000. * 3600. * 24. );
373 return static_cast<integer>( std::chrono::duration_cast<std::chrono::hours>(
span ).count()
383 return static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(
span ).count() )
384 / (1000000. * 3600. );
393 return static_cast<integer>( std::chrono::duration_cast<std::chrono::hours>(
span ).count() );
402 return static_cast<double>( std::chrono::duration_cast<std::chrono::microseconds>(
span ).count() )
412 return std::chrono::duration_cast<std::chrono::minutes>(
span ).count();
421 return static_cast<double>( std::chrono::duration_cast<std::chrono::nanoseconds>(
span ).count() )
431 return std::chrono::duration_cast<std::chrono::seconds>(
span ).count();
440 return static_cast<double>( std::chrono::duration_cast<std::chrono::nanoseconds>(
span ).count() )
450 return std::chrono::duration_cast<std::chrono::milliseconds>(
span ).count();
459 return static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(
span ).count())
469 return std::chrono::duration_cast<std::chrono::microseconds>(
span ).count();
478 return std::chrono::duration_cast<std::chrono::nanoseconds>(
span ).count();
489 double InHertz(
int qtyFractionalDigits= -1 )
const
492 if (
span.count() == 0)
496 double hz= 1000000000.0 /
static_cast<double>(
InNanoseconds());
499 if ( qtyFractionalDigits < 0 )
503 double mag= pow( 10, qtyFractionalDigits );
504 return static_cast<int>( hz * mag + ( hz < 0 ? -0.5 : 0.5 ) )
517 return std::chrono::duration_cast<TDuration>(
518 std::chrono::hours(24) * days );
529 return std::chrono::duration_cast<TDuration>(
530 std::chrono::hours(24) * days );
541 return std::chrono::duration_cast<TDuration>(
542 std::chrono::hours(1) * hours );
553 return std::chrono::duration_cast<TDuration>(
554 std::chrono::hours(1) * hours );
565 return std::chrono::duration_cast<TDuration>(
566 std::chrono::minutes(1) * minutes );
577 return std::chrono::duration_cast<TDuration>(
578 std::chrono::minutes(1) * minutes );
589 return std::chrono::duration_cast<TDuration>(
590 std::chrono::seconds(1) * seconds );
601 return std::chrono::duration_cast<TDuration>(
602 std::chrono::seconds(1) * seconds );
613 return std::chrono::duration_cast<TDuration>(
614 std::chrono::milliseconds(1) * milliseconds );
625 return std::chrono::duration_cast<TDuration>(
626 std::chrono::milliseconds(1) * milliseconds );
637 return std::chrono::duration_cast<TDuration>(
638 std::chrono::microseconds(1) * microseconds );
649 return std::chrono::duration_cast<TDuration>(
650 std::chrono::microseconds(1) * microseconds );
661 return std::chrono::duration_cast<TDuration>(
662 std::chrono::nanoseconds( nanoseconds ) );
698 stamp= TClock::now();
709 return TDerived(TClock::now());
719 stamp= TClock::now();
720 return *
static_cast<TDerived*
>(
this);
731 :
stamp(internalValue)
795 return stamp.time_since_epoch().count();
816 return TDerived(
TTimePoint(
typename TClock::duration( raw ) ) );
826 return stamp + std::chrono::duration_cast<typename TClock::duration>( timeSpan.
span );
836 stamp+= std::chrono::duration_cast<typename TClock::duration>( timeSpan.
span );
847 return stamp - std::chrono::duration_cast<typename TClock::duration>( timeSpan.
span );
899 return (*
this) - other;
912 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)
Duration operator-(const Duration &rhs) const
int64_t InAbsoluteSeconds() const
Duration & SetMaximum(const Duration &other)
static Duration FromMicroseconds(double microseconds)
bool operator<=(const Duration &other) const
Duration operator+(const Duration &rhs) const
Duration operator*(int64_t multiplier) const
Duration & operator*=(double multiplier)
static Duration Import(TDuration timeSpan)
Duration & operator+=(const Duration &other)
Duration operator*(double multiplier) const
static Duration FromAbsoluteMilliseconds(int64_t milliseconds)
static Duration FromHours(double hours)
integer InAbsoluteHours() const
int64_t InAbsoluteMinutes() const
bool operator==(const Duration &other) const
static Duration FromMilliseconds(double milliseconds)
typename std::chrono::steady_clock::duration TDuration
Duration operator/(double divisor) const
bool operator!=(const Duration &other) const
int64_t InNanoseconds() const
static Duration FromAbsoluteSeconds(int64_t seconds)
static Duration FromAbsoluteHours(int64_t hours)
Duration & operator/=(int64_t divisor)
int64_t InAbsoluteMicroseconds() const
static Duration FromAbsoluteMinutes(int64_t minutes)
Duration & operator/=(double divisor)
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
double InMicroseconds() const
static Duration FromSeconds(double seconds)
static Duration FromMinutes(double minutes)
Duration(TDuration internalValue)
static Duration FromAbsoluteDays(int64_t days)
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
void SetFromRaw(TRaw raw)
bool IsOlderThan(Duration timeSpan) const
TDerived operator+(const Duration &timeSpan) const
typename TClock::time_point TTimePoint
Duration Since(const TDerived &other) const
TDerived operator-=(const Duration &timeSpan)
TDerived operator+=(const Duration &timeSpan)
typename TTimePoint::rep TRaw
TTimePoint Export() const
void Import(TTimePoint timePoint)
constexpr TimePointBase(TTimePoint internalValue)
constexpr TimePointBase(lang::Initialization init=lang::Initialization::Perform)
static TDerived FromRaw(TRaw raw)
#define ALIB_ASSERT_MODULE(modulename)
lang::integer integer
Type alias in namespace alib.