summaryrefslogtreecommitdiff
path: root/absl/time/internal/cctz/src/time_zone_lookup.cc
diff options
context:
space:
mode:
Diffstat (limited to 'absl/time/internal/cctz/src/time_zone_lookup.cc')
-rw-r--r--absl/time/internal/cctz/src/time_zone_lookup.cc14
1 files changed, 13 insertions, 1 deletions
diff --git a/absl/time/internal/cctz/src/time_zone_lookup.cc b/absl/time/internal/cctz/src/time_zone_lookup.cc
index f2d151e4..4a68c7d5 100644
--- a/absl/time/internal/cctz/src/time_zone_lookup.cc
+++ b/absl/time/internal/cctz/src/time_zone_lookup.cc
@@ -4,7 +4,7 @@
// 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
+// 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,
@@ -20,6 +20,11 @@
#include <dlfcn.h>
#endif
#endif
+
+#if defined(__APPLE__)
+#include <CoreFoundation/CFTimeZone.h>
+#endif
+
#include <cstdlib>
#include <cstring>
#include <string>
@@ -121,6 +126,11 @@ time_zone local_time_zone() {
char* tz_env = nullptr;
#if defined(_MSC_VER)
_dupenv_s(&tz_env, nullptr, "TZ");
+#elif defined(__APPLE__)
+ CFTimeZoneRef system_time_zone = CFTimeZoneCopySystem();
+ CFStringRef tz_name = CFTimeZoneGetName(system_time_zone);
+ tz_env = strdup(CFStringGetCStringPtr(tz_name, CFStringGetSystemEncoding()));
+ CFRelease(system_time_zone);
#else
tz_env = std::getenv("TZ");
#endif
@@ -153,6 +163,8 @@ time_zone local_time_zone() {
#if defined(_MSC_VER)
free(localtime_env);
free(tz_env);
+#elif defined(__APPLE__)
+ free(tz_env);
#endif
time_zone tz;