mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 02:37:36 +02:00
Fix formatting of timezone names
This commit is contained in:
@ -1390,7 +1390,7 @@ class tm_writer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void on_utc_offset(numeric_system ns) { format_utc_offset_impl(tm_, ns); }
|
void on_utc_offset(numeric_system ns) { format_utc_offset_impl(tm_, ns); }
|
||||||
void on_tz_name() { out_ = std::copy_n("UTC", 3, out_); }
|
void on_tz_name() { format_tz_name_impl(tm_); }
|
||||||
|
|
||||||
void on_year(numeric_system ns, pad_type pad) {
|
void on_year(numeric_system ns, pad_type pad) {
|
||||||
if (is_classic_ || ns == numeric_system::standard)
|
if (is_classic_ || ns == numeric_system::standard)
|
||||||
|
@ -337,26 +337,43 @@ TEST(chrono_test, local_time) {
|
|||||||
|
|
||||||
template <typename T,
|
template <typename T,
|
||||||
FMT_ENABLE_IF(fmt::detail::has_member_data_tm_gmtoff<T>::value)>
|
FMT_ENABLE_IF(fmt::detail::has_member_data_tm_gmtoff<T>::value)>
|
||||||
bool set_gmtoff(T& time, long offset) {
|
bool set_tm_gmtoff(T& time, long offset) {
|
||||||
time.tm_gmtoff = offset;
|
time.tm_gmtoff = offset;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
template <typename T,
|
template <typename T,
|
||||||
FMT_ENABLE_IF(!fmt::detail::has_member_data_tm_gmtoff<T>::value)>
|
FMT_ENABLE_IF(!fmt::detail::has_member_data_tm_gmtoff<T>::value)>
|
||||||
bool set_gmtoff(T&, long) {
|
bool set_tm_gmtoff(T&, long) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T,
|
||||||
|
FMT_ENABLE_IF(fmt::detail::has_member_data_tm_zone<T>::value)>
|
||||||
|
bool set_tm_zone(T& time, char* tz) {
|
||||||
|
time.tm_zone = tz;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
template <typename T,
|
||||||
|
FMT_ENABLE_IF(!fmt::detail::has_member_data_tm_zone<T>::value)>
|
||||||
|
bool set_tm_zone(T&, char*) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(chrono_test, tm) {
|
TEST(chrono_test, tm) {
|
||||||
auto time = fmt::gmtime(290088000);
|
auto time = fmt::gmtime(290088000);
|
||||||
test_time(time);
|
test_time(time);
|
||||||
if (set_gmtoff(time, -28800)) {
|
if (set_tm_gmtoff(time, -28800)) {
|
||||||
EXPECT_EQ(fmt::format(fmt::runtime("{:%z}"), time), "-0800");
|
EXPECT_EQ(fmt::format(fmt::runtime("{:%z}"), time), "-0800");
|
||||||
EXPECT_EQ(fmt::format(fmt::runtime("{:%Ez}"), time), "-08:00");
|
EXPECT_EQ(fmt::format(fmt::runtime("{:%Ez}"), time), "-08:00");
|
||||||
EXPECT_EQ(fmt::format(fmt::runtime("{:%Oz}"), time), "-08:00");
|
EXPECT_EQ(fmt::format(fmt::runtime("{:%Oz}"), time), "-08:00");
|
||||||
} 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");
|
||||||
|
}
|
||||||
|
char tz[] = "EET";
|
||||||
|
if (set_tm_zone(time, tz)) {
|
||||||
|
EXPECT_EQ(fmt::format(fmt::runtime("{:%Z}"), time), "EET");
|
||||||
|
} 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");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user