LLVM: lib/Support/Chrono.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
10#include "llvm/Config/llvm-config.h"
14
15namespace llvm {
16
17using namespace sys;
18
25
27 struct tm Storage;
28 std::time_t OurTime = toTimeT(TP);
29
30#if defined(LLVM_ON_UNIX)
31 struct tm *LT = ::localtime_r(&OurTime, &Storage);
33 (void)LT;
34#endif
35#if defined(_WIN32)
36 int Error = ::localtime_s(&Storage, &OurTime);
39#endif
40
41 return Storage;
42}
43
45 struct tm Storage;
46 std::time_t OurTime = toTimeT(TP);
47
48#if defined(LLVM_ON_UNIX)
49 struct tm *LT = ::gmtime_r(&OurTime, &Storage);
51 (void)LT;
52#endif
53#if defined(_WIN32)
54 int Error = ::gmtime_s(&Storage, &OurTime);
57#endif
58
59 return Storage;
60}
61
64 char Buffer[sizeof("YYYY-MM-DD HH:MM:SS")];
65 strftime(Buffer, sizeof(Buffer), "%Y-%m-%d %H:%M:%S", <);
66 return OS << Buffer << '.'
68 long((TP.time_since_epoch() % std::chrono::seconds(1))
69 .count()));
70}
71
72template
75 using namespace std::chrono;
76
77 if (Style.empty()) Style = "%Y-%m-%d %H:%M:%S.%N";
80 for (unsigned I = 0; I < Style.size(); ++I) {
81 if (Style[I] == '%' && Style.size() > I + 1) switch (Style[I + 1]) {
82 case 'L':
84 "%.3lu", (long)duration_cast(Fractional).count());
85 ++I;
86 continue;
87 case 'f':
89 "%.6lu", (long)duration_cast(Fractional).count());
90 ++I;
91 continue;
92 case 'N':
94 "%.9lu", (long)duration_cast(Fractional).count());
95 ++I;
96 continue;
97 case '%':
98 FStream << "%%";
99 ++I;
100 continue;
101 }
102 FStream << Style[I];
103 }
105 char Buffer[256];
106 size_t Len = strftime(Buffer, sizeof(Buffer), Format.c_str(), <);
107 OS << (Len ? Buffer : "BAD-DATE-FORMAT");
108}
109
110void format_provider<UtcTimestd::chrono::seconds>::format(
112 using namespace std::chrono;
115 auto Fractional = T - Truncated;
118}
119
122 using namespace std::chrono;
124 auto Fractional = T - Truncated;
127}
128
129}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Lightweight error class with error context and mandatory checking.
StringRef - Represent a constant reference to a string, i.e.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
std::chrono::time_point< UtcClock, D > UtcTime
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.
std::time_t toTimeT(TimePoint<> TP)
Convert a TimePoint to std::time_t.
This is an optimization pass for GlobalISel generic memory operations.
static struct tm getStructTM(TimePoint<> TP)
Definition Chrono.cpp:26
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
static struct tm getStructTMUtc(UtcTime<> TP)
Definition Chrono.cpp:44
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
static const char value[]