Skip to content

Commit 9711ea3

Browse files
mralephCommit Queue
authored andcommitted
[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 #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: #55240 Change-Id: I11fb963ec90055db168c7f34bdf7c58229085bd1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358440 Reviewed-by: Siva Annamalai <asiva@google.com> Commit-Queue: Kevin Chisholm <kevinjchisholm@google.com>
1 parent ac06ea0 commit 9711ea3

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

runtime/vm/os_win.cc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,11 @@ const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) {
112112
}
113113

114114
// Figure out whether we're in standard or daylight.
115-
bool daylight_savings = (status == TIME_ZONE_ID_DAYLIGHT);
116-
if (status == TIME_ZONE_ID_UNKNOWN) {
117-
tm local_time;
118-
if (LocalTime(seconds_since_epoch, &local_time)) {
119-
daylight_savings = (local_time.tm_isdst == 1);
120-
}
115+
tm local_time;
116+
if (!LocalTime(seconds_since_epoch, &local_time)) {
117+
return "";
121118
}
119+
const bool daylight_savings = (local_time.tm_isdst == 1);
122120

123121
// Convert the wchar string to a null-terminated utf8 string.
124122
wchar_t* wchar_name = daylight_savings ? zone_information.DaylightName

tests/corelib/date_time7_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ testLocal() {
3434
Expect.equals(-4, offset.inHours);
3535
case "PDT" || "Pacific Daylight Time":
3636
Expect.equals(-7, offset.inHours);
37+
case "PST" || "Pacific Standard Time":
38+
Expect.equals(-8, offset.inHours);
3739
case "CST" || "Central Standard Time":
3840
Expect.equals(-6, offset.inHours);
3941
case "CDT" || "Central Daylight Time":

0 commit comments

Comments
 (0)