-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NPLB] Support SetTimeZone extension on win and Xbox
- Loading branch information
Marek Biolik
committed
Oct 21, 2024
1 parent
8a9e441
commit 2fb481f
Showing
6 changed files
with
200 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2024 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "starboard/extension/time_zone.h" | ||
#include "starboard/time_zone.h" | ||
#include "starboard/common/log.h" | ||
|
||
#include <string> | ||
#include <Windows.h> | ||
|
||
namespace starboard { | ||
namespace shared { | ||
namespace win32 { | ||
|
||
namespace { | ||
|
||
bool SetTimeZone(const char* time_zone_name) { | ||
std::string tzName(time_zone_name); | ||
std::wstring windowsTzName(tzName.begin(), tzName.end()); | ||
|
||
DYNAMIC_TIME_ZONE_INFORMATION dtzi{0}; | ||
TIME_ZONE_INFORMATION tzi{0}; | ||
int index = 0; | ||
bool found = false; | ||
|
||
while (EnumDynamicTimeZoneInformation(index, &dtzi) == ERROR_SUCCESS) { | ||
if (windowsTzName == dtzi.TimeZoneKeyName || | ||
windowsTzName == dtzi.StandardName || | ||
windowsTzName == dtzi.DaylightName) { | ||
found = true; | ||
break; | ||
} | ||
index++; | ||
} | ||
if (!found) { | ||
SB_LOG(ERROR) << "Time zone: " << tzName.c_str() << "not found."; | ||
return false; | ||
} | ||
auto result = SetDynamicTimeZoneInformation(&dtzi); | ||
if (result == 0) { | ||
DWORD error = GetLastError(); | ||
SB_LOG(ERROR) << "SetDynamicTimeZoneInformation failed for time zone: " | ||
<< tzName.c_str() << " return code: " << result | ||
<< " last error: " << error; | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
const StarboardExtensionTimeZoneApi kTimeZoneApi = { | ||
kStarboardExtensionTimeZoneName, | ||
1, // API version that's implemented. | ||
&SetTimeZone, | ||
}; | ||
|
||
} // namespace | ||
const void* GetTimeZoneApi() { | ||
return &kTimeZoneApi; | ||
} | ||
|
||
} // namespace win32 | ||
} // namespace shared | ||
} // namespace starboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2024 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef STARBOARD_SHARED_WIN32_TIME_ZONE_H_ | ||
#define STARBOARD_SHARED_WIN32_TIME_ZONE_H_ | ||
|
||
namespace starboard { | ||
namespace shared { | ||
namespace win32 { | ||
|
||
const void* GetTimeZoneApi(); | ||
|
||
} // namespace win32 | ||
} // namespace shared | ||
} // namespace starboard | ||
|
||
#endif // STARBOARD_SHARED_WIN32_TIME_ZONE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters