Time point: update tests and remove setting TZ
This commit is contained in:
parent
39a934b5e9
commit
e6fd5e8432
@ -95,32 +95,15 @@ TEST(TimeTest, GMTime) {
|
|||||||
EXPECT_TRUE(EqualTime(tm, fmt::gmtime(t)));
|
EXPECT_TRUE(EqualTime(tm, fmt::gmtime(t)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
# define ENV(key, val) _putenv_s(key, val)
|
|
||||||
#else
|
|
||||||
# define ENV(key, val) setenv(key, val, 1)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
TEST(TimeTest, TimePoint) {
|
TEST(TimeTest, TimePoint) {
|
||||||
ENV("TZ", "EST+5");
|
std::chrono::system_clock::time_point point = std::chrono::system_clock::now();
|
||||||
tzset();
|
|
||||||
std::chrono::system_clock::time_point point(std::chrono::seconds(1598412345));
|
|
||||||
EXPECT_EQ("It is 2020-08-25 22:25:45.",
|
|
||||||
fmt::format("It is {:%Y-%m-%d %H:%M:%S}.", point));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(TimeTest, LocalTimeWithTimePoint) {
|
std::time_t t = std::chrono::system_clock::to_time_t(point);
|
||||||
ENV("TZ", "EST+5");
|
std::tm tm = *std::localtime(&t);
|
||||||
tzset();
|
char strftime_output[256];
|
||||||
std::chrono::system_clock::time_point point(std::chrono::seconds(1598412345));
|
std::strftime(strftime_output, sizeof(strftime_output), "It is %Y-%m-%d %H:%M:%S", &tm);
|
||||||
EXPECT_EQ("It is 2020-08-25 22:25:45.",
|
|
||||||
fmt::format("It is {:%Y-%m-%d %H:%M:%S}.", fmt::localtime(point)));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(TimeTest, GMTimeWithTimePoint) {
|
EXPECT_EQ(strftime_output, fmt::format("It is {:%Y-%m-%d %H:%M:%S}", point));
|
||||||
std::chrono::system_clock::time_point point(std::chrono::seconds(1598412345));
|
|
||||||
EXPECT_EQ("It is 2020-08-26 03:25:45 UTC.",
|
|
||||||
fmt::format("It is {:%Y-%m-%d %H:%M:%S} UTC.", fmt::gmtime(point)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define EXPECT_TIME(spec, time, duration) \
|
#define EXPECT_TIME(spec, time, duration) \
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user