Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ cc_test(
],
)

cc_test(
name = "time_zone_name_win_test",
size = "small",
srcs = ["src/time_zone_name_win_test.cc"],
target_compatible_with = ["@platforms//os:windows"],
deps = [
":time_zone",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
)

cc_test(
name = "time_zone_fuzz_test",
srcs = [
Expand Down
20 changes: 17 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ if (BUILD_TESTING)
${CMAKE_THREAD_LIBS_INIT}
)
add_test(civil_time_test civil_time_test)
list(APPEND CCTZ_TESTS civil_time_test)

add_executable(time_zone_lookup_test src/time_zone_lookup_test.cc)
cctz_target_set_cxx_standard(time_zone_lookup_test)
Expand All @@ -138,6 +139,7 @@ if (BUILD_TESTING)
${CMAKE_THREAD_LIBS_INIT}
)
add_test(time_zone_lookup_test time_zone_lookup_test)
list(APPEND CCTZ_TESTS time_zone_lookup_test)

add_executable(time_zone_format_test src/time_zone_format_test.cc)
cctz_target_set_cxx_standard(time_zone_format_test)
Expand All @@ -147,13 +149,25 @@ if (BUILD_TESTING)
GMock::Main
)
add_test(time_zone_format_test time_zone_format_test)
list(APPEND CCTZ_TESTS time_zone_format_test)

if(WIN32)
add_executable(time_zone_name_win_test src/time_zone_name_win_test.cc)
cctz_target_set_cxx_standard(time_zone_name_win_test)
target_include_directories(time_zone_name_win_test PRIVATE ${GTEST_INCLUDE_DIRS})
target_link_libraries(time_zone_name_win_test
cctz::cctz
${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
add_test(time_zone_name_win_test time_zone_name_win_test)
list(APPEND CCTZ_TESTS time_zone_name_win_test)
endif()

# tests runs on testdata
set_property(
TEST
civil_time_test
time_zone_format_test
time_zone_lookup_test
${CCTZ_TESTS}
PROPERTY
ENVIRONMENT "TZDIR=${CMAKE_CURRENT_SOURCE_DIR}/testdata/zoneinfo"
)
Expand Down
2 changes: 1 addition & 1 deletion src/time_zone_name_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ ucal_getTimeZoneIDForWindowsID_func LoadIcuGetTimeZoneIDForWindowsID() {
const auto ucal_getTimeZoneIDForWindowsIDRef =
AsProcAddress<ucal_getTimeZoneIDForWindowsID_func>(
icu_dll, "ucal_getTimeZoneIDForWindowsID");
if (ucal_getTimeZoneIDForWindowsIDRef != nullptr) {
if (ucal_getTimeZoneIDForWindowsIDRef == nullptr) {
Comment thread
yukawa marked this conversation as resolved.
g_unavailable.store(true, std::memory_order_relaxed);
return nullptr;
}
Expand Down
42 changes: 42 additions & 0 deletions src/time_zone_name_win_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2026 Google Inc. 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
//
// https://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 "time_zone_name_win.h"

#include <string>

#include <windows.h>

#include "cctz/time_zone.h"
#include "gtest/gtest.h"

namespace cctz {

TEST(TimeZoneNameWin, GetWindowsLocalTimeZone) {
// On Windows 10 1809+ (where icu.dll is available in System32),
// GetWindowsLocalTimeZone() should return a valid IANA time zone name.
// Note that LOAD_LIBRARY_SEARCH_SYSTEM32 is not sufficient to reliably load
// "icu.dll" in the production code, but it should be OK for testing purposes.
HMODULE icu_dll =
::LoadLibraryExW(L"icu.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
const std::string tz = GetWindowsLocalTimeZone();
if (icu_dll != nullptr) {
EXPECT_FALSE(tz.empty());
::FreeLibrary(icu_dll);
} else {
EXPECT_TRUE(tz.empty());
}
Comment on lines +34 to +39
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My final question before handing off to @derekmauro.

Do we know which branch our Windows CI actually takes? That is, is it checking that GetWindowsLocalTimeZone() succeeds or fails?

Copy link
Copy Markdown
Contributor Author

@yukawa yukawa Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should go to icu_dll != nullptr route, so GetWindowsLocalTimeZone() should now be continuously tested in CI.

According to a recent run, runner image is windows-2025, which should have icu.dll there.

Runner Image
Image: windows-2025

}

} // namespace cctz