NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
time.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_TIME_HPP
23 #define NDN_TIME_HPP
24 
25 #include "../common.hpp"
26 #include <boost/chrono.hpp>
27 #include <boost/asio/time_traits.hpp>
28 #include <boost/date_time/posix_time/posix_time_types.hpp>
29 
30 namespace ndn {
31 namespace time {
32 
33 using boost::chrono::duration;
34 
35 typedef duration<boost::int_least32_t, boost::ratio<86400> > days;
36 using boost::chrono::hours;
37 using boost::chrono::minutes;
38 using boost::chrono::seconds;
39 
40 using boost::chrono::milliseconds;
41 using boost::chrono::microseconds;
42 using boost::chrono::nanoseconds;
43 
44 using boost::chrono::duration_cast;
45 
70 {
71 public:
72  typedef BOOST_SYSTEM_CLOCK_DURATION duration;
73  typedef duration::rep rep;
74  typedef duration::period period;
75  typedef boost::chrono::time_point<system_clock> time_point;
76  static constexpr bool is_steady = false;
77 
78  typedef time_point TimePoint;
79  typedef duration Duration;
80 
81  static time_point
82  now() noexcept;
83 
84  static std::time_t
85  to_time_t(const time_point& t) noexcept;
86 
87  static time_point
88  from_time_t(std::time_t t) noexcept;
89 }; // class system_clock
90 
100 {
101 public:
102  typedef nanoseconds duration;
103  typedef duration::rep rep;
104  typedef duration::period period;
105  typedef boost::chrono::time_point<steady_clock> time_point;
106  static constexpr bool is_steady = true;
107 
108  typedef time_point TimePoint;
109  typedef duration Duration;
110 
111  static time_point
112  now() noexcept;
113 
114 private:
123  static boost::posix_time::time_duration
124  to_posix_duration(const duration& duration);
125 
126  friend struct boost::asio::time_traits<steady_clock>;
127 }; // class steady_clock
128 
129 
133 const system_clock::TimePoint&
134 getUnixEpoch();
135 
139 milliseconds
140 toUnixTimestamp(const system_clock::TimePoint& point);
141 
145 system_clock::TimePoint
146 fromUnixTimestamp(const milliseconds& duration);
147 
161 std::string
162 toIsoString(const system_clock::TimePoint& timePoint);
163 
176 system_clock::TimePoint
177 fromIsoString(const std::string& isoString);
178 
192 std::string
193 toString(const system_clock::TimePoint& timePoint,
194  const std::string& format = "%Y-%m-%d %H:%M:%S",
195  const std::locale& locale = std::locale("C"));
196 
210 system_clock::TimePoint
211 fromString(const std::string& formattedTimePoint,
212  const std::string& format = "%Y-%m-%d %H:%M:%S",
213  const std::locale& locale = std::locale("C"));
214 
215 
217 
218 } // namespace time
219 } // namespace ndn
220 
221 namespace boost {
222 namespace chrono {
223 
224 template<class CharT>
225 struct clock_string<ndn::time::system_clock, CharT>
226 {
227  static std::basic_string<CharT>
228  since();
229 };
230 
231 template<class CharT>
232 struct clock_string<ndn::time::steady_clock, CharT>
233 {
234  static std::basic_string<CharT>
235  since();
236 };
237 
238 } // namespace chrono
239 } // namespace boost
240 
241 #endif // NDN_TIME_HPP
boost::chrono::time_point< system_clock > time_point
Definition: time.hpp:75
time_point TimePoint
Definition: time.hpp:108
boost::chrono::time_point< steady_clock > time_point
Definition: time.hpp:105
Copyright (c) 2011-2015 Regents of the University of California.
system_clock::TimePoint fromIsoString(const std::string &isoString)
Convert from the ISO string (YYYYMMDDTHHMMSS,fffffffff) representation to the internal time format...
Definition: time.cpp:147
Copyright (c) 2013-2015 Regents of the University of California.
duration::period period
Definition: time.hpp:74
BOOST_SYSTEM_CLOCK_DURATION duration
Definition: time.hpp:72
static std::time_t to_time_t(const time_point &t) noexcept
Definition: time.cpp:57
static constexpr bool is_steady
Definition: time.hpp:76
duration::period period
Definition: time.hpp:104
nanoseconds duration
Definition: time.hpp:102
STL namespace.
Steady clock.
Definition: time.hpp:99
static time_point now() noexcept
Definition: time.cpp:45
std::string toString(const system_clock::TimePoint &timePoint, const std::string &format, const std::locale &locale)
Convert time point to string with specified format.
Definition: time.cpp:162
system_clock::TimePoint fromString(const std::string &formattedTimePoint, const std::string &format, const std::locale &locale)
Convert from string of specified format into time point.
Definition: time.cpp:182
duration::rep rep
Definition: time.hpp:73
System clock.
Definition: time.hpp:69
std::string toIsoString(const system_clock::TimePoint &timePoint)
Convert to the ISO string representation of the time (YYYYMMDDTHHMMSS,fffffffff)
Definition: time.cpp:130
time_point TimePoint
Definition: time.hpp:78
system_clock::TimePoint fromUnixTimestamp(const milliseconds &duration)
Convert UNIX timestamp to system_clock::TimePoint.
Definition: time.cpp:124
milliseconds toUnixTimestamp(const system_clock::TimePoint &point)
Convert system_clock::TimePoint to UNIX timestamp.
Definition: time.cpp:118
duration::rep rep
Definition: time.hpp:103
static time_point from_time_t(std::time_t t) noexcept
Definition: time.cpp:63
const system_clock::TimePoint & getUnixEpoch()
Get system_clock::TimePoint representing UNIX time epoch (00:00:00 on Jan 1, 1970) ...
Definition: time.cpp:111
duration< boost::int_least32_t, boost::ratio< 86400 > > days
Definition: time.hpp:35