Classes | Namespaces | Macros | Functions
time.h File Reference
#include "format.h"
#include <ctime>
#include <locale>

Go to the source code of this file.

Classes

struct  formatter< std::tm, Char >
 

Namespaces

 internal
 

Macros

#define FMT_NOMACRO
 

Functions

null localtime_r internal::FMT_NOMACRO (...)
 
null internal::localtime_s (...)
 
null internal::gmtime_r (...)
 
null internal::gmtime_s (...)
 
std::tm localtime (std::time_t time)
 
std::tm gmtime (std::time_t time)
 
std::size_t internal::strftime (char *str, std::size_t count, const char *format, const std::tm *time)
 
std::size_t internal::strftime (wchar_t *str, std::size_t count, const wchar_t *format, const std::tm *time)
 

Macro Definition Documentation

#define FMT_NOMACRO

Definition at line 19 of file time.h.

Function Documentation

std::tm gmtime ( std::time_t  time)
inline

Definition at line 67 of file time.h.

67  {
68  struct dispatcher {
69  std::time_t time_;
70  std::tm tm_;
71 
72  dispatcher(std::time_t t): time_(t) {}
73 
74  bool run() {
75  using namespace fmt::internal;
76  return handle(gmtime_r(&time_, &tm_));
77  }
78 
79  bool handle(std::tm *tm) { return tm != FMT_NULL; }
80 
81  bool handle(internal::null<>) {
82  using namespace fmt::internal;
83  return fallback(gmtime_s(&tm_, &time_));
84  }
85 
86  bool fallback(int res) { return res == 0; }
87 
88 #if !FMT_MSC_VER
89  bool fallback(internal::null<>) {
90  std::tm *tm = std::gmtime(&time_);
91  if (tm) tm_ = *tm;
92  return tm != FMT_NULL;
93  }
94 #endif
95  };
96  dispatcher gt(time);
97  // Too big time values may be unsupported.
98  if (!gt.run())
99  FMT_THROW(format_error("time_t value out of range"));
100  return gt.tm_;
101 }
null gmtime_s(...)
Definition: time.h:25
null gmtime_r(...)
Definition: time.h:24
#define FMT_THROW(x)
Definition: format.h:115
std::tm gmtime(std::time_t time)
Definition: time.h:67
#define FMT_NULL
Definition: core.h:107
unsigned int run
std::tm localtime ( std::time_t  time)
inline

Definition at line 29 of file time.h.

29  {
30  struct dispatcher {
31  std::time_t time_;
32  std::tm tm_;
33 
34  dispatcher(std::time_t t): time_(t) {}
35 
36  bool run() {
37  using namespace fmt::internal;
38  return handle(localtime_r(&time_, &tm_));
39  }
40 
41  bool handle(std::tm *tm) { return tm != FMT_NULL; }
42 
43  bool handle(internal::null<>) {
44  using namespace fmt::internal;
45  return fallback(localtime_s(&tm_, &time_));
46  }
47 
48  bool fallback(int res) { return res == 0; }
49 
50 #if !FMT_MSC_VER
51  bool fallback(internal::null<>) {
52  using namespace fmt::internal;
53  std::tm *tm = std::localtime(&time_);
54  if (tm) tm_ = *tm;
55  return tm != FMT_NULL;
56  }
57 #endif
58  };
59  dispatcher lt(time);
60  // Too big time values may be unsupported.
61  if (!lt.run())
62  FMT_THROW(format_error("time_t value out of range"));
63  return lt.tm_;
64 }
#define FMT_THROW(x)
Definition: format.h:115
null localtime_s(...)
Definition: time.h:23
std::tm localtime(std::time_t time)
Definition: time.h:29
#define FMT_NULL
Definition: core.h:107
unsigned int run