Public Types | Public Member Functions | Public Attributes | List of all members
internal::chrono_formatter< FormatContext, OutputIt > Struct Template Reference

#include <chrono.h>

Public Types

typedef FormatContext::char_type char_type
 

Public Member Functions

 chrono_formatter (FormatContext &ctx, OutputIt o)
 
int hour () const
 
int hour12 () const
 
int minute () const
 
int second () const
 
std::tm time () const
 
void write (int value, int width)
 
void format_localized (const tm &time, const char *format)
 
void on_text (const char_type *begin, const char_type *end)
 
void on_abbr_weekday ()
 
void on_full_weekday ()
 
void on_dec0_weekday (numeric_system)
 
void on_dec1_weekday (numeric_system)
 
void on_abbr_month ()
 
void on_full_month ()
 
void on_datetime (numeric_system)
 
void on_loc_date (numeric_system)
 
void on_loc_time (numeric_system)
 
void on_us_date ()
 
void on_iso_date ()
 
void on_utc_offset ()
 
void on_tz_name ()
 
void on_24_hour (numeric_system ns)
 
void on_12_hour (numeric_system ns)
 
void on_minute (numeric_system ns)
 
void on_second (numeric_system ns)
 
void on_12_hour_time ()
 
void on_24_hour_time ()
 
void on_iso_time ()
 
void on_am_pm ()
 

Public Attributes

FormatContext & context
 
OutputIt out
 
std::chrono::seconds s
 
std::chrono::milliseconds ms
 

Detailed Description

template<typename FormatContext, typename OutputIt>
struct internal::chrono_formatter< FormatContext, OutputIt >

Definition at line 221 of file chrono.h.

Member Typedef Documentation

template<typename FormatContext, typename OutputIt>
typedef FormatContext::char_type internal::chrono_formatter< FormatContext, OutputIt >::char_type

Definition at line 227 of file chrono.h.

Constructor & Destructor Documentation

template<typename FormatContext, typename OutputIt>
internal::chrono_formatter< FormatContext, OutputIt >::chrono_formatter ( FormatContext &  ctx,
OutputIt  o 
)
inlineexplicit

Definition at line 229 of file chrono.h.

230  : context(ctx), out(o) {}
FormatContext & context
Definition: chrono.h:222

Member Function Documentation

template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::format_localized ( const tm &  time,
const char *  format 
)
inline

Definition at line 259 of file chrono.h.

259  {
260  auto locale = context.locale().template get<std::locale>();
261  auto &facet = std::use_facet<std::time_put<char_type>>(locale);
262  std::basic_ostringstream<char_type> os;
263  os.imbue(locale);
264  facet.put(os, os, ' ', &time, format, format + std::strlen(format));
265  auto str = os.str();
266  std::copy(str.begin(), str.end(), out);
267  }
locale_ref locale()
Definition: core.h:1040
std::string str(const std::pair< Type, Type > &tt)
Definition: test_pimpos.cxx:12
T copy(T const &v)
template<typename FormatContext, typename OutputIt>
int internal::chrono_formatter< FormatContext, OutputIt >::hour ( ) const
inline

Definition at line 232 of file chrono.h.

232 { return to_int((s.count() / 3600) % 24); }
std::chrono::seconds s
Definition: chrono.h:224
int to_int(Int value)
Definition: chrono.h:214
template<typename FormatContext, typename OutputIt>
int internal::chrono_formatter< FormatContext, OutputIt >::hour12 ( ) const
inline

Definition at line 234 of file chrono.h.

234  {
235  auto hour = to_int((s.count() / 3600) % 12);
236  return hour > 0 ? hour : 12;
237  }
std::chrono::seconds s
Definition: chrono.h:224
int to_int(Int value)
Definition: chrono.h:214
template<typename FormatContext, typename OutputIt>
int internal::chrono_formatter< FormatContext, OutputIt >::minute ( ) const
inline

Definition at line 239 of file chrono.h.

239 { return to_int((s.count() / 60) % 60); }
std::chrono::seconds s
Definition: chrono.h:224
int to_int(Int value)
Definition: chrono.h:214
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_12_hour ( numeric_system  ns)
inline

Definition at line 296 of file chrono.h.

296  {
298  return write(hour12(), 2);
299  auto time = tm();
300  time.tm_hour = hour();
301  format_localized(time, "%OI");
302  }
int hour12() const
Definition: chrono.h:234
void format_localized(const tm &time, const char *format)
Definition: chrono.h:259
void write(int value, int width)
Definition: chrono.h:250
QAsciiDict< Entry > ns
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_12_hour_time ( )
inline

Definition at line 326 of file chrono.h.

326 { format_localized(time(), "%r"); }
std::tm time() const
Definition: chrono.h:242
void format_localized(const tm &time, const char *format)
Definition: chrono.h:259
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_24_hour ( numeric_system  ns)
inline

Definition at line 288 of file chrono.h.

288  {
290  return write(hour(), 2);
291  auto time = tm();
292  time.tm_hour = hour();
293  format_localized(time, "%OH");
294  }
void format_localized(const tm &time, const char *format)
Definition: chrono.h:259
void write(int value, int width)
Definition: chrono.h:250
QAsciiDict< Entry > ns
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_24_hour_time ( )
inline

Definition at line 328 of file chrono.h.

328  {
329  write(hour(), 2);
330  *out++ = ':';
331  write(minute(), 2);
332  }
int minute() const
Definition: chrono.h:239
void write(int value, int width)
Definition: chrono.h:250
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_abbr_month ( )
inline

Definition at line 278 of file chrono.h.

278 {}
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_abbr_weekday ( )
inline

Definition at line 274 of file chrono.h.

274 {}
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_am_pm ( )
inline

Definition at line 340 of file chrono.h.

340 { format_localized(time(), "%p"); }
std::tm time() const
Definition: chrono.h:242
void format_localized(const tm &time, const char *format)
Definition: chrono.h:259
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_datetime ( numeric_system  )
inline

Definition at line 280 of file chrono.h.

280 {}
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_dec0_weekday ( numeric_system  )
inline

Definition at line 276 of file chrono.h.

276 {}
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_dec1_weekday ( numeric_system  )
inline

Definition at line 277 of file chrono.h.

277 {}
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_full_month ( )
inline

Definition at line 279 of file chrono.h.

279 {}
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_full_weekday ( )
inline

Definition at line 275 of file chrono.h.

275 {}
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_iso_date ( )
inline

Definition at line 284 of file chrono.h.

284 {}
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_iso_time ( )
inline

Definition at line 334 of file chrono.h.

334  {
335  on_24_hour_time();
336  *out++ = ':';
337  write(second(), 2);
338  }
int second() const
Definition: chrono.h:240
void write(int value, int width)
Definition: chrono.h:250
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_loc_date ( numeric_system  )
inline

Definition at line 281 of file chrono.h.

281 {}
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_loc_time ( numeric_system  )
inline

Definition at line 282 of file chrono.h.

282 {}
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_minute ( numeric_system  ns)
inline

Definition at line 304 of file chrono.h.

304  {
306  return write(minute(), 2);
307  auto time = tm();
308  time.tm_min = minute();
309  format_localized(time, "%OM");
310  }
int minute() const
Definition: chrono.h:239
void format_localized(const tm &time, const char *format)
Definition: chrono.h:259
void write(int value, int width)
Definition: chrono.h:250
QAsciiDict< Entry > ns
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_second ( numeric_system  ns)
inline

Definition at line 312 of file chrono.h.

312  {
313  if (ns == numeric_system::standard) {
314  write(second(), 2);
315  if (ms != std::chrono::milliseconds(0)) {
316  *out++ = '.';
317  write(to_int(ms.count()), 3);
318  }
319  return;
320  }
321  auto time = tm();
322  time.tm_sec = second();
323  format_localized(time, "%OS");
324  }
int second() const
Definition: chrono.h:240
void format_localized(const tm &time, const char *format)
Definition: chrono.h:259
millisecond milliseconds
Alias for common language habits.
Definition: spacetime.h:100
int to_int(Int value)
Definition: chrono.h:214
std::chrono::milliseconds ms
Definition: chrono.h:225
void write(int value, int width)
Definition: chrono.h:250
QAsciiDict< Entry > ns
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_text ( const char_type begin,
const char_type end 
)
inline

Definition at line 269 of file chrono.h.

269  {
270  std::copy(begin, end, out);
271  }
FMT_CONSTEXPR auto begin(const C &c) -> decltype(c.begin())
Definition: format.h:251
FMT_CONSTEXPR auto end(const C &c) -> decltype(c.end())
Definition: format.h:257
T copy(T const &v)
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_tz_name ( )
inline

Definition at line 286 of file chrono.h.

286 {}
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_us_date ( )
inline

Definition at line 283 of file chrono.h.

283 {}
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::on_utc_offset ( )
inline

Definition at line 285 of file chrono.h.

285 {}
template<typename FormatContext, typename OutputIt>
int internal::chrono_formatter< FormatContext, OutputIt >::second ( ) const
inline

Definition at line 240 of file chrono.h.

240 { return to_int(s.count() % 60); }
std::chrono::seconds s
Definition: chrono.h:224
int to_int(Int value)
Definition: chrono.h:214
template<typename FormatContext, typename OutputIt>
std::tm internal::chrono_formatter< FormatContext, OutputIt >::time ( ) const
inline

Definition at line 242 of file chrono.h.

242  {
243  auto time = std::tm();
244  time.tm_hour = hour();
245  time.tm_min = minute();
246  time.tm_sec = second();
247  return time;
248  }
std::tm time() const
Definition: chrono.h:242
int second() const
Definition: chrono.h:240
int minute() const
Definition: chrono.h:239
template<typename FormatContext, typename OutputIt>
void internal::chrono_formatter< FormatContext, OutputIt >::write ( int  value,
int  width 
)
inline

Definition at line 250 of file chrono.h.

250  {
251  typedef typename int_traits<int>::main_type main_type;
252  main_type n = to_unsigned(value);
253  int num_digits = internal::count_digits(n);
254  if (width > num_digits)
255  out = std::fill_n(out, width - num_digits, '0');
256  out = format_decimal<char_type>(out, n, num_digits);
257  }
const double width
FMT_CONSTEXPR std::make_unsigned< Int >::type to_unsigned(Int value)
Definition: core.h:208
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
std::size_t n
Definition: format.h:3399
int count_digits(uint64_t n)
Definition: format.h:777

Member Data Documentation

template<typename FormatContext, typename OutputIt>
FormatContext& internal::chrono_formatter< FormatContext, OutputIt >::context

Definition at line 222 of file chrono.h.

template<typename FormatContext, typename OutputIt>
std::chrono::milliseconds internal::chrono_formatter< FormatContext, OutputIt >::ms

Definition at line 225 of file chrono.h.

template<typename FormatContext, typename OutputIt>
OutputIt internal::chrono_formatter< FormatContext, OutputIt >::out

Definition at line 223 of file chrono.h.

template<typename FormatContext, typename OutputIt>
std::chrono::seconds internal::chrono_formatter< FormatContext, OutputIt >::s

Definition at line 224 of file chrono.h.


The documentation for this struct was generated from the following file: