Skip to content

Commit b282144

Browse files
committed
Fix handling of %Z
1 parent 6d69f0c commit b282144

3 files changed

Lines changed: 4 additions & 18 deletions

File tree

.github/workflows/windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
4040

4141
- name: Set timezone
42-
run: tzutil /s "Ekaterinburg Standard Time"
42+
run: tzutil /s "Pacific Standard Time"
4343

4444
- name: Create Build Environment
4545
run: cmake -E make_directory ${{runner.workspace}}/build

include/fmt/chrono.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ class tm_writer {
13931393
}
13941394

13951395
void on_utc_offset(numeric_system ns) { format_utc_offset_impl(tm_, ns); }
1396-
void on_tz_name() { format_tz_name_impl(tm_); }
1396+
void on_tz_name() { out_ = std::copy_n("UTC", 3, out_); }
13971397

13981398
void on_year(numeric_system ns, pad_type pad) {
13991399
if (is_classic_ || ns == numeric_system::standard)

test/chrono-test.cc

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ auto strftime_full_utc(TimePoint tp) -> std::string {
263263
return system_strftime("%Y-%m-%d %H:%M:%S", &tm);
264264
}
265265

266-
template <typename Time>
267-
void test_time(Time time) {
266+
template <typename Time> void test_time(Time time) {
268267
EXPECT_EQ(fmt::format("{}", time), "1979-03-12 12:00:00");
269268
EXPECT_EQ(fmt::format("{:}", time), "1979-03-12 12:00:00");
270269

@@ -333,20 +332,7 @@ TEST(chrono_test, sys_time) {
333332
EXPECT_EQ(fmt::format("{:%z}", time), "+0000");
334333
EXPECT_EQ(fmt::format("{:%Ez}", time), "+00:00");
335334
EXPECT_EQ(fmt::format("{:%Oz}", time), "+00:00");
336-
337-
auto t1 = std::chrono::time_point_cast<std::chrono::seconds>(
338-
std::chrono::system_clock::now());
339-
340-
// Separate tests for UTC, since std::time_put can use local time and ignoring
341-
// the timezone in std::tm (if it presents on platform).
342-
if (fmt::detail::has_member_data_tm_zone<std::tm>::value) {
343-
auto t = std::chrono::system_clock::to_time_t(t1);
344-
auto tm = *std::gmtime(&t);
345-
346-
std::vector<std::string> tz_names = {"GMT", "UTC"};
347-
EXPECT_THAT(tz_names, Contains(fmt::format("{:%Z}", t1)));
348-
EXPECT_THAT(tz_names, Contains(fmt::format("{:%Z}", tm)));
349-
}
335+
EXPECT_EQ(fmt::format("{:%Z}", time), "UTC");
350336
}
351337

352338
TEST(chrono_test, local_time) {

0 commit comments

Comments
 (0)