| 
									
										
										
										
											2018-07-21 22:57:21 +08:00
										 |  |  | #include "..\e2dcommon.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace std::chrono; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::Time::Time() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | time_t e2d::Time::GetTimeStamp() const | 
					
						
							| 
									
										
										
										
											2018-07-21 22:57:21 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	auto& duration = time_point_cast<milliseconds>(time_).time_since_epoch(); | 
					
						
							| 
									
										
										
										
											2018-07-29 01:43:15 +08:00
										 |  |  | 	return static_cast<time_t>(duration.count()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | bool e2d::Time::IsZero() const | 
					
						
							| 
									
										
										
										
											2018-07-29 01:43:15 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	return time_.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-08-02 00:27:45 +08:00
										 |  |  | 	Time t; | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	t.time_ = time_ + milliseconds(other.Milliseconds()); | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  | 	return std::move(t); | 
					
						
							| 
									
										
										
										
											2018-07-22 21:22:27 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  | e2d::Time e2d::Time::operator-(Duration const & other) const | 
					
						
							| 
									
										
										
										
											2018-07-22 21:22:27 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  | 	Time t; | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	t.time_ = time_ - milliseconds(other.Milliseconds()); | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  | 	return std::move(t); | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  | e2d::Time & e2d::Time::operator+=(Duration const & other) | 
					
						
							| 
									
										
										
										
											2018-07-29 01:43:15 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	time_ += milliseconds(other.Milliseconds()); | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  | 	return (*this); | 
					
						
							| 
									
										
										
										
											2018-07-29 01:43:15 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::Time & e2d::Time::operator-=(Duration const &other) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	time_ -= milliseconds(other.Milliseconds()); | 
					
						
							| 
									
										
										
										
											2018-07-29 01:43:15 +08:00
										 |  |  | 	return (*this); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | e2d::Duration e2d::Time::operator-(Time const & other) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	auto ms = duration_cast<milliseconds>(time_ - other.time_).count(); | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  | 	return std::move(Duration(static_cast<float>(ms) / 1000.f)); | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | e2d::Time e2d::Time::Now() | 
					
						
							| 
									
										
										
										
											2018-07-22 00:41:24 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  | 	Time t; | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	t.time_ = steady_clock::now(); | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  | 	return std::move(t); | 
					
						
							| 
									
										
										
										
											2018-07-21 22:57:21 +08:00
										 |  |  | } |