Skip to content

Commit

Permalink
[stable][vm] Fix DateTime.timeZoneName on Windows
Browse files Browse the repository at this point in the history
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: Id4b593edfb4f0df967ff04d72efa86f320cc4e8f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358420
Reviewed-by: Siva Annamalai <[email protected]>
Commit-Queue: Kevin Chisholm <[email protected]>
  • Loading branch information
mraleph authored and Commit Queue committed Mar 19, 2024
1 parent 2ed9775 commit b8a6290
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ This is a patch release that:
[#55158][]).
- Fixes an issue in the CFE that prevented redirecting factories from being
resolved in initializers of extension types (issue [#55194][]).
- Fixes an issues with VM's implementation of `DateTime.timeZoneName`
on Windows, which was checking whether current date is in the summer or
standard time rather than checking if the given moment is in the summer or
standard time (issue [#55240][]).

[#55158]: https://github.com/dart-lang/sdk/issues/55158
[#55194]: https://github.com/dart-lang/sdk/issues/55194
[#55240]: https://github.com/dart-lang/sdk/issues/55240

## 3.3.1 - 2024-03-06

Expand Down
10 changes: 4 additions & 6 deletions runtime/vm/os_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/corelib/date_time7_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down

0 comments on commit b8a6290

Please sign in to comment.