From 9711ea3f34b5ca1c2e0eded9b43053e5f32dfba3 Mon Sep 17 00:00:00 2001 From: Vyacheslav Egorov Date: Tue, 19 Mar 2024 19:54:32 +0000 Subject: [PATCH] [beta][vm] Fix DateTime.timeZoneName on Windows It needs to look at the given moment to decide whether to use summer time zone name or standard time zone name. Previously it was looking at the current time to make this decision which produced incorrect result: e.g. given `DateTime.parse(2012-01-02T13:45:23)` its `timeZoneName` should be returning standard name corresponding to the current time zone even if we are currently running in summer time (e.g. it should return PST if machine it is running on is in PDT). This is revealed by a test which started to fail on Windows because our Windows bots entered PDT. Fixes https://github.com/dart-lang/sdk/issues/55159 TEST=corelib/date_time7_test.dart CoreLibraryReviewExempt: No core library changes. Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/356681 Cherry-pick-request: https://github.com/dart-lang/sdk/issues/55240 Change-Id: I11fb963ec90055db168c7f34bdf7c58229085bd1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358440 Reviewed-by: Siva Annamalai Commit-Queue: Kevin Chisholm --- runtime/vm/os_win.cc | 10 ++++------ tests/corelib/date_time7_test.dart | 2 ++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/runtime/vm/os_win.cc b/runtime/vm/os_win.cc index 9daec00e6f3c..9e5ea5519aaa 100644 --- a/runtime/vm/os_win.cc +++ b/runtime/vm/os_win.cc @@ -112,13 +112,11 @@ const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) { } // Figure out whether we're in standard or daylight. - bool daylight_savings = (status == TIME_ZONE_ID_DAYLIGHT); - if (status == TIME_ZONE_ID_UNKNOWN) { - tm local_time; - if (LocalTime(seconds_since_epoch, &local_time)) { - daylight_savings = (local_time.tm_isdst == 1); - } + tm local_time; + if (!LocalTime(seconds_since_epoch, &local_time)) { + return ""; } + const bool daylight_savings = (local_time.tm_isdst == 1); // Convert the wchar string to a null-terminated utf8 string. wchar_t* wchar_name = daylight_savings ? zone_information.DaylightName diff --git a/tests/corelib/date_time7_test.dart b/tests/corelib/date_time7_test.dart index f59236a040ce..576c13eff26b 100644 --- a/tests/corelib/date_time7_test.dart +++ b/tests/corelib/date_time7_test.dart @@ -34,6 +34,8 @@ testLocal() { Expect.equals(-4, offset.inHours); case "PDT" || "Pacific Daylight Time": Expect.equals(-7, offset.inHours); + case "PST" || "Pacific Standard Time": + Expect.equals(-8, offset.inHours); case "CST" || "Central Standard Time": Expect.equals(-6, offset.inHours); case "CDT" || "Central Daylight Time":