Skip to content

Commit 197d45a

Browse files
committed
Test tm timezone formatting
1 parent f10b6dd commit 197d45a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/chrono-test.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,24 @@ TEST(chrono_test, local_time) {
336336
fmt::format_error, "no timezone");
337337
}
338338

339+
template <typename T, FMT_ENABLE_IF(fmt::detail::has_member_data_tm_gmtoff<T>::value)>
340+
bool set_gmtoff(T& time, long offset) {
341+
time.tm_gmtoff = offset;
342+
return true;
343+
}
344+
template <typename T, FMT_ENABLE_IF(!fmt::detail::has_member_data_tm_gmtoff<T>::value)>
345+
bool set_gmtoff(T&, long) {
346+
return false;
347+
}
348+
339349
TEST(chrono_test, tm) {
340350
auto time = fmt::gmtime(290088000);
341351
test_time(time);
352+
if (set_gmtoff(time, -28800)) {
353+
EXPECT_EQ(fmt::format(fmt::runtime("{:%z}"), time), "-0800");
354+
EXPECT_EQ(fmt::format(fmt::runtime("{:%Ez}"), time), "-08:00");
355+
EXPECT_EQ(fmt::format(fmt::runtime("{:%Oz}"), time), "-08:00");
356+
}
342357
}
343358

344359
TEST(chrono_test, daylight_savings_time_end) {

0 commit comments

Comments
 (0)