24 #ifndef LOG4CPLUS_HELPERS_TIME_HELPER_HEADER_
25 #define LOG4CPLUS_HELPERS_TIME_HELPER_HEADER_
29 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
35 #if defined (LOG4CPLUS_HAVE_TIME_H)
50 namespace chrono = std::chrono;
52 typedef chrono::system_clock
Clock;
53 typedef chrono::duration<long long, std::micro>
Duration;
54 typedef chrono::time_point<Clock, Duration>
Time;
57 template <
typename FromDuration>
60 time_cast (chrono::time_point<Clock, FromDuration>
const & tp)
62 return chrono::time_point_cast<Duration, Clock> (tp);
91 if (rounded_time > the_time)
113 static_assert ((std::ratio_equal<Duration::period, std::micro>::value),
117 return static_cast<long>(
126 return from_time_t (tv_sec) + chrono::microseconds (tv_usec);
161 Time const & the_time,
bool use_gmtime =
false);
Time time_from_parts(time_t tv_sec, long tv_usec)
LOG4CPLUS_EXPORT log4cplus::tstring getFormattedTime(log4cplus::tstring const &fmt, Time const &the_time, bool use_gmtime=false)
Returns a string with a "formatted time" specified by fmt.
long microseconds_part(Time const &the_time)
time_t to_time_t(Time const &the_time)
LOG4CPLUS_EXPORT void gmTime(tm *t, Time const &)
Populates tm using the gmtime() function.
LOG4CPLUS_EXPORT void localTime(tm *t, Time const &)
Populates tm using the localtime() function.
chrono::duration< long long, std::micro > Duration
chrono::system_clock Clock
LOG4CPLUS_EXPORT Time from_struct_tm(tm *t)
Time time_cast(chrono::time_point< Clock, FromDuration > const &tp)
Time from_time_t(time_t t_time)
chrono::time_point< Clock, Duration > Time
Time truncate_fractions(Time const &the_time)
std::basic_string< tchar > tstring