17 #if defined(__ANDROID__) 18 #include <sys/system_properties.h> 19 #if defined(__ANDROID_API__) && __ANDROID_API__ >= 21 24 #if defined(__APPLE__) 25 #include <CoreFoundation/CFTimeZone.h> 37 namespace time_internal {
40 #if defined(__ANDROID__) && defined(__ANDROID_API__) && __ANDROID_API__ >= 21 46 using property_get_func = int (*)(
const char*,
char*);
48 property_get_func LoadSystemPropertyGet() {
49 int flag = RTLD_LAZY | RTLD_GLOBAL;
50 #if defined(RTLD_NOLOAD) 53 if (
void* handle = dlopen(
"libc.so", flag)) {
54 void* sym = dlsym(handle,
"__system_property_get");
56 return reinterpret_cast<property_get_func
>(sym);
61 int __system_property_get(
const char*
name,
char*
value) {
62 static property_get_func system_property_get = LoadSystemPropertyGet();
63 return system_property_get ? system_property_get(name, value) : -1;
101 if (
impl_ ==
nullptr) {
124 const char* zone =
":localtime";
125 #if defined(__ANDROID__) 126 char sysprop[PROP_VALUE_MAX];
127 if (__system_property_get(
"persist.sys.timezone", sysprop) > 0) {
131 #if defined(__APPLE__) 132 std::vector<char> buffer;
133 CFTimeZoneRef tz_default = CFTimeZoneCopyDefault();
134 if (CFStringRef tz_name = CFTimeZoneGetName(tz_default)) {
135 CFStringEncoding encoding = kCFStringEncodingUTF8;
136 CFIndex
length = CFStringGetLength(tz_name);
137 buffer.resize(CFStringGetMaximumSizeForEncoding(length, encoding) + 1);
138 if (CFStringGetCString(tz_name, &buffer[0], buffer.size(), encoding)) {
142 CFRelease(tz_default);
146 char* tz_env =
nullptr;
147 #if defined(_MSC_VER) 148 _dupenv_s(&tz_env,
nullptr,
"TZ");
150 tz_env = std::getenv(
"TZ");
152 if (tz_env) zone = tz_env;
155 if (*zone ==
':') ++zone;
159 char* localtime_env =
nullptr;
160 if (strcmp(zone,
"localtime") == 0) {
161 #if defined(_MSC_VER) 163 _dupenv_s(&localtime_env,
nullptr,
"LOCALTIME");
165 zone =
"/etc/localtime";
166 localtime_env = std::getenv(
"LOCALTIME");
168 if (localtime_env) zone = localtime_env;
171 const std::string
name = zone;
172 #if defined(_MSC_VER) bool next_transition(const time_point< seconds > &tp, civil_transition *trans) const
static bool LoadTimeZone(const std::string &name, time_zone *tz)
time_zone fixed_time_zone(const seconds &offset)
std::string description() const
bool NextTransition(const time_point< seconds > &tp, time_zone::civil_transition *trans) const
std::chrono::duration< std::int_fast64_t > seconds
time_zone local_time_zone()
time_zone::absolute_lookup BreakTime(const time_point< seconds > &tp) const
bool prev_transition(const time_point< seconds > &tp, civil_transition *trans) const
absolute_lookup lookup(const time_point< seconds > &tp) const
std::string Version() const
time_zone::civil_lookup MakeTime(const civil_second &cs) const
std::string version() const
std::string Description() const
std::chrono::time_point< std::chrono::system_clock, D > time_point
std::string FixedOffsetToName(const seconds &offset)
time_zone utc_time_zone()
const std::string & Name() const
bool load_time_zone(const std::string &name, time_zone *tz)
const Impl & effective_impl() const
bool PrevTransition(const time_point< seconds > &tp, time_zone::civil_transition *trans) const