Add formatters for chrono::time_point<system_clock> (#1837)

Add formatters for chrono::time_point and helper overloads for localtime/gmtime(time_point)
Fixes #1819
This commit is contained in:
Adam Burgess
2020-08-28 07:41:38 -07:00
committed by GitHub
parent 77b627be20
commit f39e6fb617
2 changed files with 32 additions and 0 deletions
+11
View File
@@ -95,6 +95,17 @@ TEST(TimeTest, GMTime) {
EXPECT_TRUE(EqualTime(tm, fmt::gmtime(t)));
}
TEST(TimeTest, TimePoint) {
std::chrono::system_clock::time_point point = std::chrono::system_clock::now();
std::time_t t = std::chrono::system_clock::to_time_t(point);
std::tm tm = *std::localtime(&t);
char strftime_output[256];
std::strftime(strftime_output, sizeof(strftime_output), "It is %Y-%m-%d %H:%M:%S", &tm);
EXPECT_EQ(strftime_output, fmt::format("It is {:%Y-%m-%d %H:%M:%S}", point));
}
#define EXPECT_TIME(spec, time, duration) \
{ \
std::locale loc("ja_JP.utf8"); \