formatTime.cc
Go to the documentation of this file.
2 
3 #include <memory>
4 #include <string>
5 
6 extern "C" {
7 #include <stdio.h>
8 #include <string.h>
9 #include <time.h>
10 }
11 
12 namespace {
13  std::size_t constexpr SIZE{144};
14 }
15 
18 {
19  return std::string{format};
20 }
21 
24 {
25  struct tm timebuf;
26  char ts[SIZE];
27  strftime(ts, sizeof(ts), format, localtime_r(&t.tv_sec, &timebuf));
28  return std::string{ts};
29 }
30 
33 {
34  struct tm timebuf;
35  char tmpts[SIZE], ts[SIZE];
36  strftime(tmpts, sizeof(tmpts), format, localtime_r(&t.tv_sec, &timebuf));
37  snprintf(ts, sizeof(ts), tmpts, static_cast<unsigned>(t.tv_usec / 1000));
38  return std::string{ts};
39 }
40 
43  std::string const& user_supplied_format)
44 {
45  struct tm timebuf;
46  char ts[SIZE];
47  strftime(ts,
48  sizeof(ts),
49  user_supplied_format.data(),
50  localtime_r(&t.tv_sec, &timebuf));
51  return std::string{ts};
52 }
static std::string get_time(timeval const &t)
Definition: formatTime.cc:23
std::string string
Definition: nybbler.cc:12
static std::string get_time(timeval const &)
Definition: formatTime.cc:17
static constexpr char const * format
Definition: formatTime.h:11
static std::string get_time(timeval const &t, std::string const &user_supplied_format)
Definition: formatTime.cc:42
static std::string get_time(timeval const &t)
Definition: formatTime.cc:32