| 
									
										
										
										
											2018-07-21 22:57:21 +08:00
										 |  |  | #include "..\e2dcommon.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace std::chrono; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::Time::Time() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-28 20:48:25 +08:00
										 |  |  | e2d::Time::Time(const std::chrono::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-22 20:09:14 +08:00
										 |  |  | 	auto& now = time_point_cast<milliseconds>(_timePoint).time_since_epoch(); | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | 	return static_cast<time_t>(now.count()); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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
										 |  |  | } |