mirror of
https://github.com/fmtlib/fmt.git
synced 2026-06-15 08:26:13 +08:00
Fix formatting std::tm with null tm_zone (#4790)
This commit is contained in:
parent
f53c0408a3
commit
a90ad5d6fd
@ -1192,6 +1192,7 @@ class tm_writer {
|
|||||||
|
|
||||||
template <typename T, FMT_ENABLE_IF(has_tm_zone<T>::value)>
|
template <typename T, FMT_ENABLE_IF(has_tm_zone<T>::value)>
|
||||||
void format_tz_name(const T& tm) {
|
void format_tz_name(const T& tm) {
|
||||||
|
if (!tm.tm_zone) FMT_THROW(format_error("no timezone"));
|
||||||
out_ = write_tm_str<Char>(out_, tm.tm_zone, loc_);
|
out_ = write_tm_str<Char>(out_, tm.tm_zone, loc_);
|
||||||
}
|
}
|
||||||
template <typename T, FMT_ENABLE_IF(!has_tm_zone<T>::value)>
|
template <typename T, FMT_ENABLE_IF(!has_tm_zone<T>::value)>
|
||||||
|
|||||||
@ -358,6 +358,9 @@ TEST(chrono_test, tm) {
|
|||||||
char tz[] = "EET";
|
char tz[] = "EET";
|
||||||
if (fmt::detail::set_tm_zone(time, tz)) {
|
if (fmt::detail::set_tm_zone(time, tz)) {
|
||||||
EXPECT_EQ(fmt::format(fmt::runtime("{:%Z}"), time), "EET");
|
EXPECT_EQ(fmt::format(fmt::runtime("{:%Z}"), time), "EET");
|
||||||
|
fmt::detail::set_tm_zone(time, nullptr);
|
||||||
|
EXPECT_THROW_MSG((void)fmt::format(fmt::runtime("{:%Z}"), time),
|
||||||
|
fmt::format_error, "no timezone");
|
||||||
} else {
|
} else {
|
||||||
EXPECT_THROW_MSG((void)fmt::format(fmt::runtime("{:%Z}"), time),
|
EXPECT_THROW_MSG((void)fmt::format(fmt::runtime("{:%Z}"), time),
|
||||||
fmt::format_error, "no timezone");
|
fmt::format_error, "no timezone");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user