MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / getSystemTimeZone

Method getSystemTimeZone

src/common/TimeZoneUtil.cpp:323–435  ·  view source on GitHub ↗

Return the current user's time zone.

Source from the content-addressed store, hash-verified

321
322// Return the current user's time zone.
323USHORT TimeZoneUtil::getSystemTimeZone()
324{
325 static volatile bool cachedError = false;
326 static volatile USHORT cachedTimeZoneId = TimeZoneUtil::GMT_ZONE;
327 static volatile int32_t cachedTimeZoneNameLen = -1;
328 static char cachedTimeZoneName[TimeZoneUtil::MAX_SIZE];
329 static GlobalPtr<RWLock> lock;
330
331 if (cachedError)
332 return cachedTimeZoneId;
333
334 // ASF: The code below in this function is prepared to detect changes in OS time zone or config setting, but
335 // the called functions are not. So cache and return directly the previously detected time zone.
336 if (cachedTimeZoneNameLen != -1)
337 return cachedTimeZoneId;
338
339 UErrorCode icuErrorCode = U_ZERO_ERROR;
340 Jrd::UnicodeUtil::ConversionICU& icuLib = Jrd::UnicodeUtil::getConversionICU();
341
342 char buffer[TimeZoneUtil::MAX_SIZE];
343 const char* str = buffer;
344 int32_t len;
345 const char* configDefault = Config::getDefaultTimeZone();
346 bool strictParse = true;
347
348 if (configDefault && configDefault[0])
349 {
350 str = configDefault;
351 len = strlen(str);
352 }
353 else
354 {
355 UChar unicodeBuffer[TimeZoneUtil::MAX_LEN];
356 len = icuLib.ucalGetDefaultTimeZone(unicodeBuffer, FB_NELEM(unicodeBuffer), &icuErrorCode);
357
358 if (!U_FAILURE(icuErrorCode))
359 {
360 UChar* src = unicodeBuffer;
361 char* dst = buffer;
362
363 while (src - unicodeBuffer < len)
364 *dst++ = (char) *src++;
365
366 str = buffer;
367 buffer[len] = '\0';
368
369 strictParse = false;
370 }
371 else
372 {
373 gds__log("ICU error (%d) retrieving the system time zone. Falling back to displacement.",
374 int(icuErrorCode));
375 }
376 }
377
378 ReadLockGuard readGuard(lock, "TimeZoneUtil::getSystemTimeZone");
379
380 if (!U_FAILURE(icuErrorCode) &&

Callers

nothing calls this directly

Calls 3

absFunction · 0.85
makeFromOffsetFunction · 0.85
releaseMethod · 0.45

Tested by

no test coverage detected