18 #pragma warning(disable : 4702) // unreachable code 19 #pragma warning(disable : 4996) // "deprecated" functions 23 template<
typename ArgFormatter>
24 void format_arg(BasicFormatter<char, ArgFormatter> &f,
const char *&format_str,
const std::tm &tm)
26 if (*format_str ==
':')
28 const char *end = format_str;
29 while (*end && *end !=
'}')
32 FMT_THROW(FormatError(
"missing '}' in format string"));
33 internal::MemoryBuffer<char, internal::INLINE_BUFFER_SIZE> format;
34 format.append(format_str, end + 1);
35 format[format.size() - 1] =
'\0';
36 Buffer<char> &buffer = f.writer().buffer();
37 std::size_t start = buffer.size();
40 std::size_t size = buffer.capacity() - start;
41 std::size_t count = std::strftime(&buffer[start], size, &format[0], &tm);
44 buffer.resize(start + count);
47 if (size >= format.size() * 256)
55 const std::size_t MIN_GROWTH = 10;
56 buffer.reserve(buffer.capacity() + (size > MIN_GROWTH ? size : MIN_GROWTH));
62 inline Null<> localtime_r(...)
66 inline Null<> localtime_s(...)
70 inline Null<> gmtime_r(...)
74 inline Null<> gmtime_s(...)
81 inline std::tm localtime(std::time_t time)
88 LocalTime(std::time_t t)
96 return handle(localtime_r(&time_, &tm_));
99 bool handle(std::tm *tm)
101 return tm != FMT_NULL;
104 bool handle(internal::Null<>)
107 return fallback(localtime_s(&tm_, &time_));
110 bool fallback(
int res)
115 bool fallback(internal::Null<>)
118 std::tm *tm = std::localtime(&time_);
121 return tm != FMT_NULL;
133 inline std::tm gmtime(std::time_t time)
140 GMTime(std::time_t t)
148 return handle(gmtime_r(&time_, &tm_));
151 bool handle(std::tm *tm)
153 return tm != FMT_NULL;
156 bool handle(internal::Null<>)
159 return fallback(gmtime_s(&tm_, &time_));
162 bool fallback(
int res)
167 bool fallback(internal::Null<>)
169 std::tm *tm = std::gmtime(&time_);
172 return tm != FMT_NULL;
188 #endif // FMT_TIME_H_