2018-07-21 22:57:21 +08:00
|
|
|
#include "..\e2dcommon.h"
|
|
|
|
|
|
|
|
|
|
using namespace std::chrono;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e2d::Time::Time()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-29 01:43:15 +08:00
|
|
|
e2d::Time::Time(const steady_clock::time_point& time)
|
2018-07-22 20:09:14 +08:00
|
|
|
: _timePoint(time)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-22 00:41:24 +08:00
|
|
|
time_t e2d::Time::getTimeStamp() const
|
2018-07-21 22:57:21 +08:00
|
|
|
{
|
2018-07-29 01:43:15 +08:00
|
|
|
auto& duration = time_point_cast<milliseconds>(_timePoint).time_since_epoch();
|
|
|
|
|
return static_cast<time_t>(duration.count());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool e2d::Time::isZero() const
|
|
|
|
|
{
|
|
|
|
|
return _timePoint.time_since_epoch().count() == 0LL;
|
2018-07-21 22:57:21 +08:00
|
|
|
}
|
|
|
|
|
|
2018-07-22 00:41:24 +08:00
|
|
|
e2d::Time e2d::Time::operator+(Duration const & other) const
|
2018-07-21 22:57:21 +08:00
|
|
|
{
|
2018-07-22 21:22:27 +08:00
|
|
|
return std::move(Time(_timePoint + milliseconds(other.milliseconds())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e2d::Time & e2d::Time::operator+=(Duration const & other)
|
|
|
|
|
{
|
|
|
|
|
_timePoint += milliseconds(other.milliseconds());
|
|
|
|
|
return (*this);
|
2018-07-22 00:41:24 +08:00
|
|
|
}
|
|
|
|
|
|
2018-07-29 01:43:15 +08:00
|
|
|
e2d::Time e2d::Time::operator-(Duration const & other) const
|
|
|
|
|
{
|
|
|
|
|
return std::move(Time(_timePoint - milliseconds(other.milliseconds())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e2d::Time & e2d::Time::operator-=(Duration const &other)
|
|
|
|
|
{
|
|
|
|
|
_timePoint -= milliseconds(other.milliseconds());
|
|
|
|
|
return (*this);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-22 00:41:24 +08:00
|
|
|
e2d::Duration e2d::Time::operator-(Time const & other) const
|
|
|
|
|
{
|
2018-07-22 20:09:14 +08:00
|
|
|
auto& ms = duration_cast<milliseconds>(_timePoint - other._timePoint);
|
2018-07-22 00:41:24 +08:00
|
|
|
return std::move(Duration(ms));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e2d::Time e2d::Time::now()
|
|
|
|
|
{
|
2018-07-22 20:09:14 +08:00
|
|
|
return std::move(Time(steady_clock::now()));
|
2018-07-21 22:57:21 +08:00
|
|
|
}
|