9 #include "../common.hpp"
10 #include <boost/chrono.hpp>
11 #include <boost/date_time/posix_time/posix_time.hpp>
16 using boost::chrono::duration;
18 typedef duration<boost::int_least32_t, boost::ratio<86400> >
days;
19 using boost::chrono::hours;
20 using boost::chrono::minutes;
21 using boost::chrono::seconds;
23 using boost::chrono::milliseconds;
24 using boost::chrono::microseconds;
25 using boost::chrono::nanoseconds;
27 using boost::chrono::duration_cast;
78 boost::chrono::system_clock
80 boost::chrono::steady_clock
109 return duration_cast<milliseconds>(point -
getUnixEpoch());
137 namespace bpt = boost::posix_time;
138 bpt::ptime ptime = bpt::from_time_t(system_clock::to_time_t(timePoint));
140 uint64_t micro = duration_cast<microseconds>(timePoint -
getUnixEpoch()).count() % 1000000;
143 ptime += bpt::microseconds(micro);
144 return bpt::to_iso_string(ptime);
147 return bpt::to_iso_string(ptime);
165 namespace bpt = boost::posix_time;
166 static bpt::ptime posixTimeEpoch = bpt::from_time_t(0);
168 bpt::ptime ptime = bpt::from_iso_string(isoString);
171 system_clock::from_time_t((ptime - posixTimeEpoch).total_seconds());
172 point += microseconds((ptime - posixTimeEpoch).total_microseconds() % 1000000);
191 const std::string& format =
"%Y-%m-%d %H:%M:%S",
192 const std::locale& locale = std::locale(
"C"))
194 namespace bpt = boost::posix_time;
195 bpt::ptime ptime = bpt::from_time_t(system_clock::to_time_t(timePoint));
197 uint64_t micro = duration_cast<microseconds>(timePoint -
getUnixEpoch()).count() % 1000000;
198 ptime += bpt::microseconds(micro);
200 bpt::time_facet* facet =
new bpt::time_facet(format.c_str());
201 std::ostringstream formattedTimePoint;
202 formattedTimePoint.imbue(std::locale(locale, facet));
203 formattedTimePoint << ptime;
205 return formattedTimePoint.str();
223 const std::string& format =
"%Y-%m-%d %H:%M:%S",
224 const std::locale& locale = std::locale(
"C"))
226 namespace bpt = boost::posix_time;
227 static bpt::ptime posixTimeEpoch = bpt::from_time_t(0);
229 bpt::time_input_facet* facet =
new bpt::time_input_facet(format);
230 std::istringstream is(formattedTimePoint);
232 is.imbue(std::locale(locale, facet));
237 system_clock::from_time_t((ptime - posixTimeEpoch).total_seconds());
238 point += microseconds((ptime - posixTimeEpoch).total_microseconds() % 1000000);
245 #endif // NDN_TIME_HPP
system_clock::TimePoint fromIsoString(const std::string &isoString)
Convert from the ISO string (YYYYMMDDTHHMMSS,fffffffff) representation to the internal time format...
const system_clock::TimePoint & getUnixEpoch()
Get system_clock::TimePoint representing UNIX time epoch (00:00:00 on Jan 1, 1970) ...
std::string toString(const system_clock::TimePoint &timePoint, const std::string &format="%Y-%m-%d %H:%M:%S", const std::locale &locale=std::locale("C"))
Convert time point to string with specified format.
system_clock::TimePoint fromString(const std::string &formattedTimePoint, const std::string &format="%Y-%m-%d %H:%M:%S", const std::locale &locale=std::locale("C"))
Convert from string of specified format into time point.
std::string toIsoString(const system_clock::TimePoint &timePoint)
Convert to the ISO string representation of the time (YYYYMMDDTHHMMSS,fffffffff)
system_clock::TimePoint fromUnixTimestamp(const milliseconds &duration)
Convert UNIX timestamp to system_clock::TimePoint.
milliseconds toUnixTimestamp(const system_clock::TimePoint &point)
Convert system_clock::TimePoint to UNIX timestamp.
duration< boost::int_least32_t, boost::ratio< 86400 > > days