1 #if !defined(sol_date_time_utc_time_hpp_included)
2 #define sol_date_time_utc_time_hpp_included
3 /// \addtogroup sol_date_time
8 * \file sol/date_time/utc_time.hpp
9 * \brief UTC time similar to time_t but with nanosecond resolution
10 * \author Sven Suursoho
14 #include <sol/date_time/duration.hpp>
17 namespace sol
{ namespace date_time
{
21 * UTC time similar to std::time_t but with higher resolution
22 * (internally nanosecond, but depending on operating system and hardware
23 * platform it is probably lower)
29 /// Storage type for number of nanoseconds since Epoch
30 typedef nanoseconds::tick_type tick_type
;
33 /// Number of ticks per second
34 static tick_type
const ticks_per_second
= nanoseconds::ticks_per_second
;
37 /// Number of seconds per tick
38 static tick_type
const seconds_per_tick
= nanoseconds::seconds_per_tick
;
41 /// True if resolution is less than 1 second
42 static bool const is_subsecond
= nanoseconds::is_subsecond
;
45 /// Zero time (i.e. Epoch)
56 /// Return number of seconds since Epoch
58 seconds_since_epoch () const
60 return time_
/nanoseconds::ticks_per_second
;
64 /// Return number of nanoseconds since Epoch
66 nanoseconds_since_epoch () const
72 /// Return true if this == that
74 operator== (utc_time
const &that
) const
76 return time_
== that
.time_
;
80 /// Return true if this != that
82 operator!= (utc_time
const &that
) const
84 return time_
!= that
.time_
;
88 /// Return true if this > that
90 operator> (utc_time
const &that
) const
92 return time_
> that
.time_
;
96 /// Return true if this >= that
98 operator>= (utc_time
const &that
) const
100 return time_
>= that
.time_
;
104 /// Return true if this < that
106 operator< (utc_time
const &that
) const
108 return time_
< that
.time_
;
112 /// Return true if this <= that
114 operator<= (utc_time
const &that
) const
116 return time_
<= that
.time_
;
120 /// Return duration between this and that
122 operator- (utc_time
const &that
) const
124 return nanoseconds(time_
- that
.time_
);
128 /// Shift time point by \a d
129 template <typename DurationType
>
131 operator+ (DurationType
const &d
) const
134 return utc_time(time_
+ ns
.get_count());
138 /// Shift this time point by \a d
139 template <typename DurationType
>
141 operator+= (DurationType
const &d
)
144 time_
+= ns
.get_count();
149 /// Shift time point by \a d
150 template <typename DurationType
>
152 operator- (DurationType
const &d
) const
155 return utc_time(time_
- ns
.get_count());
159 /// Shift this time point by \a d
160 template <typename DurationType
>
162 operator-= (DurationType
const &d
)
165 time_
-= ns
.get_count();
172 friend class hiresolution_clock
;
174 utc_time (nanoseconds::tick_type t
)
178 nanoseconds::tick_type time_
;
182 }} // namespace sol::date_time
186 #endif // sol_date_time_utc_time_hpp_included