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:
@@ -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"); \
|
||||
|
||||
Reference in New Issue
Block a user